-
Notifications
You must be signed in to change notification settings - Fork 95
Fix buffer size when binary data is returned in multipart response #145
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
Conversation
VERSION
Outdated
| @@ -1 +1 @@ | |||
| 1.7.0 | |||
| 1.7.1 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not change the version inside the PR. While in this case it will probably go out just after merge, such practice would create problems for us very easily (imagine multiple PRs). It is better to leave the version management up to maintainers.
Also, what actually would save us time, would be the update of CHANGELOG.md :)
pyodata/v2/service.py
Outdated
| dict(response.getheaders()), | ||
| response.status, | ||
| response.read(len(data)) # the len here will give a 'big enough' value to read the whole content | ||
| response.read(sys.getsizeof(data)) # the getsizeof here will actually give a 'big enough' value to read the whole content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a fix for a bug, could you please capture it with a test?
Pls add new test to test_service_v2.py, ideally one that would reproduce the bug before your fix and pass after your fix. This is relevant to big binary file, but you don't need to commit such big file (pls don't, git repo will be smaller :) ), just generate it inside the test.
|
Apart from the line comment, your change fails builds because of linter failure. Relevant for you is the:
Sadly, together with your change came new version of pylint, so other two failures are not relevant, but new rules applied to old code. I have fixed this in PR #146, so now the upgrade of linters will happen deterministically and with its own build-per-PR. Pls pull from master into your branch , so the build will pass and we can merge the PR. You can run the linter locally with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix. Please refer to the comments what needs to be changed so this can be merged.
Also the CLA needs to be signed, check on the PR the respective check. I have updated the CONTRIBUTING.md so its necessity is more clear, you can now refer to it for any PR.
|
Hi @bartonip, I'd like to anwer #issuecomment-1011475876 here, because it's related to this issue.
I agree, that's probably a bug, that will truncate the response body and I think this will happen, when there are many multibyte characters in the payload. The len is taken including the header, so the bug will be effective, if the extra bytes of the multibyte characters are more than the size of the header.
However, if you receive arbitrary binary data, you will have "surprises" anyway. Like you've noted before, the data is decoded as UTF-8 (actually I think this happens in pyodata, not in the requests library). Not every arbitrary series of bytes is valid UTF-8 (e.g. The OData spec knows different primitive types and defines a specific encoding for each of them. There is no type, that permits the server to send arbitrary binary data (except when adressing the As the affected lines of code are called through a few indirections, it's really guesswork to say, how you could run into this bug. So if you did, could you boil this down to a reproducer or even a testcase? |
|
Yep the situation where I've run into receiving pure binary data is receiving it through the The encoding of the string becomes irrelevant when using I will work on a test case this weekend, although no promises as I am not familiar with this codebase anymore. |
bdc4f15 to
1710d96
Compare
|
Hi @bartonip I understand that you do not want to work on this PR anymore. But since you came into contact with this bug - and seems still valid for me - could you please provide if not test that reproduces the problem, at least attach a file with response that creates problem with the I was not able to reproduce your problem and seems @inxonic was not able as well. |
When binary data is returned in a response,
lenis not sufficient to determine the required buffer size.getsizeofhas been used instead to provide a more accurate buffer value.