Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-749

Handle non-integer chunk sizes in GridFS

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Blocker - P1 Blocker - P1
    • 2.8, 3.0
    • Affects Version/s: 2.7.2
    • Component/s: None
    • None
    • Environment:
      OS:Centos python:2.6

      The unofficial Lua driver can insert chunks into GridFS with float-type chunkSize. For example, the chunkSize might be "261120.0" instead of "261120" (BSON type 0x01 instead of type 0x10 or 0x12.) Perhaps PyMongo should handle this buggy input better.

      Exception info:

      File "/usr/lib64/python2.6/site-packages/pymongo-2.7-py2.6-linux-x86_64.egg/gridfs/grid_file.py", line 482, in read
          chunk_data = self.readchunk()
        File "/usr/lib64/python2.6/site-packages/pymongo-2.7-py2.6-linux-x86_64.egg/gridfs/grid_file.py", line 454, in readchunk
          chunk_data = chunk["data"][self.__position % self.chunk_size:]
      TypeError: slice indices must be integers or None or have an __index__ method
      

      Is chunk_size only int? Or int and float all are ok?

      I found a way that modifies 'grid_file.py:454' from 'chunk_data = chunk["data"][self.__position % self.chunk_size:]' to 'chunk_data = chunk["data"][self.__position % int(self.chunk_size):]' to fix the bug.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            fenghui2013 fenghui2013
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: