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

InvalidBodyLengthError #1252

Closed
WEDeach opened this issue Apr 13, 2021 · 2 comments
Closed

InvalidBodyLengthError #1252

WEDeach opened this issue Apr 13, 2021 · 2 comments

Comments

@WEDeach
Copy link

WEDeach commented Apr 13, 2021

Hello! I am using the http2 function in httpx to connect to some services
The service has binary encrypted data, and the content-length of the response represents the length I need to decrypt

And this caused the InvalidBodyLengthError in the h2 module

File "C:\Users\20191121\AppData\Local\Programs\Python\Python36\lib\site-packages\h2\stream.py", line 1337, in _track_content_length raise InvalidBodyLengthError(expected, actual)
h2.exceptions.InvalidBodyLengthError: InvalidBodyLengthError: Expected 116 bytes, received 132

I tried to annotate the line of code in h2\stream.py, and it working, so I am curious why need to raise the error?

If it is to check for security, should you add parameters so that users can bypass the check?

@vmagamedov
Copy link
Contributor

https://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2.6 says that such response is malformed and MUST NOT be accepted.

Just checked that curl also raises PROTOCOL_ERROR when you provide wrong content-length header. You can also try curl this way with your server:

$ curl --http2 --http2-prior-knowledge -v https://...

I think that this issue requires more of investigation on your side.

@WEDeach
Copy link
Author

WEDeach commented Apr 15, 2021

I checked it again

when I using http2, it will get wrong content-length (116).
when using http1.1, it got the correct content-length (132).

I’m sorry, it seems to be a problem from the server, although I don’t know why the server respond wrong content-length
but now, close this

@WEDeach WEDeach closed this as completed Apr 15, 2021
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

No branches or pull requests

2 participants