[JAVA-2548] GridFSDownloadStreamImpl.skip() can't handle >2GB Created: 07/Jul/17  Updated: 29/Oct/23  Resolved: 11/Jul/17

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: 3.4.2
Fix Version/s: 3.5.0

Type: Bug Priority: Major - P3
Reporter: Rustam Abdullaev Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

After calling GridFSDownloadStreamImpl.skip() with a value larger than 2GB, e.g. 2306734080, the subsequent read() fails with ArrayIndexOutOfBoundsException.

It seems like this casting is missing some parentheses at line 117:

        bufferOffset = (int) skippedPosition % chunkSizeInBytes;

This is in effect:

        bufferOffset = ((int) skippedPosition) % chunkSizeInBytes;

But should have been:

        bufferOffset = (int) skippedPosition % chunkSizeInBytes;

The same applies here at line 126:

Math.floor((float) skippedPosition / chunkSizeInBytes)

(Why float by the way, and not double?)



 Comments   
Comment by Githook User [ 10/Jul/17 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Fix casting in GridFSDownloadImpl

JAVA-2548
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/98d872ecaa4029779e35147aefc50f98d79d49ba

Comment by Ross Lawley [ 10/Jul/17 ]

PR: https://github.com/rozza/mongo-java-driver/pull/206

Comment by Ross Lawley [ 10/Jul/17 ]

Thanks for the ticket rustyx and identifying the cause. I've scheduled a fix for the 3.5 release.

Comment by Rustam Abdullaev [ 07/Jul/17 ]

I mean it should have been

        bufferOffset = (int) (skippedPosition % chunkSizeInBytes);

Generated at Thu Feb 08 08:57:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.