Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Filestore unable to read sizes smaller than offset #1907

Conversation

kounelisagis
Copy link
Member

In Filestore class, in the read() method this line size = max(size - offset, 0) does not cover the case of trying to read a size that is smaller than the offset. Consider a 4 byte file. If we want to read the last byte (offset 3, size 1) this check sets the size to 0 incorrectly.

Changing it to size = min(size, len(self) - offset) ensures that we read either the specified size or the remaining length of the file store starting from the offset, whichever is smaller.

Copy link

This pull request has been linked to Shortcut Story #39340: Python filestore unable to read sizes smaller than offset.

Copy link
Member

@ihnorton ihnorton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a test?

Copy link
Member

@ihnorton ihnorton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kounelisagis kounelisagis merged commit 42c8e3d into dev Mar 1, 2024
34 checks passed
@kounelisagis kounelisagis deleted the agis/sc-39340/python-filestore-unable-to-read-sizes-smaller-than-offset branch March 1, 2024 22:02
kounelisagis added a commit that referenced this pull request Mar 4, 2024
* Fix filestore unable to read sizes smaller than offset
* add test for filestore using small buffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants