Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2740

mongoc_gridfs_file_readv aborts when a chunk is larger than chunkSize

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.13.0
    • Affects Version/s: 1.11.0
    • Component/s: GridFS, libmongoc
    • None

      To reproduce:

      1. create a normal gridfs file in server side
      2. corrupt the server side data by updating the binary data with data length larger than chunk size
        e.g. by issuing the following update script on gridfs .chunks collection
        db.getCollection("test.chunks").update( { _id: ObjectId("5b44698c5e82244456e061c3") }, { _id: ObjectId("5b44698c5e82244456e061c3"), "files_id": ObjectId("5b44698a7fe4771ab4002304"), n: NumberInt("0"), data: BinData(0, "iVBOR.....RK5CYII=") } );
        

        note: the binary data length has to be larger than the defined gridfs file chunk size

      1. in client side, issue the following call
        mongoc_gridfs_file_readv(...)
        
      2. it will cause an BSON_ASSERT (len <= chunk_size); since the len of this page is larger than the chunk_size
        mongoc_gridfs_file_page_t *
        _mongoc_gridfs_file_page_new (const uint8_t *data,
                                      uint32_t len,
                                      uint32_t chunk_size)
        {
           mongoc_gridfs_file_page_t *page;
        
           ENTRY;
        
           BSON_ASSERT (data);
           BSON_ASSERT (len <= chunk_size);
        
           page = (mongoc_gridfs_file_page_t *) bson_malloc0 (sizeof *page);
        
           page->chunk_size = chunk_size;
           page->read_buf = data;
           page->len = len;
        
           RETURN (page);
        }
        

      Client side library should check for this corrupted case, instead of asserting the execution?
      At the moment, there is no way to do a precaution checking without inspecting the low level raw .chunks collection

      The libmongoc should be fixed, since server side data corruption should not assert client side execution.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            ben.prect Ben Cheong
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: