CDRIVER-5506 error if mongoc_gridfs_file_readv
reads an incomplete chunk
#1565
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Address a hang observed in
mongoc_gridfs_file_readv
when reading a corrupt incomplete chunk. If an incomplete chunk is detected, an error is now returned.Background & Motivation
Though the
mongoc_gridfs_t
API notably does not conform to the GridFS spec, the GridFS spec requires returning an error for an unexpected length:The cause of the hang is an assumption that chunks (excluding the last) contain data of length chunk size.
_mongoc_gridfs_file_refresh_page
calculates the chunk to read from the position of the last read byte:If an incomplete chunk is read,
file->pos
may be smaller than assumed, resulting in repeated setting offile->n
to an already-read chunk.