fix: catch std::out_of_range when parsing inference header length in HTTP frontends - #8925
Open
akhilraj9 wants to merge 5 commits into
Open
fix: catch std::out_of_range when parsing inference header length in HTTP frontends#8925akhilraj9 wants to merge 5 commits into
akhilraj9 wants to merge 5 commits into
Conversation
…erver crash (TRI-1636) std::stoi throws std::out_of_range for values outside [INT_MIN, INT_MAX] but GetInferenceHeaderLength in all three HTTP frontends only caught invalid_argument, letting an oversized header value escape into libevhtp's C event loop and crash the server.
…fix-inference-header-length-out-of-range
…(TRI-1636) Add test_inference_header_content_length_out_of_range to L0_http, test_malformed_binary_header_out_of_range to L0_sagemaker and L0_vertex_ai. Each test sends a header value of 99999999999 (exceeds INT_MAX) and asserts the server returns 400 and remains live — verifying the std::out_of_range catch added to GetInferenceHeaderLength prevents the server crash.
The L0_http, L0_sagemaker and L0_vertex_ai harnesses assert an exact number of executed unit tests. Adding one out_of_range regression test to each file raised the counts to 17/10/9, so update EXPECTED_NUM_TESTS / UNIT_TEST_COUNT accordingly.
Greptile SummaryThe PR prevents oversized inference-header length values from escaping HTTP handlers as uncaught
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "ci: satisfy pre-commit hooks (flake8 E40..." | Re-trigger Greptile |
Member
|
@akhilraj9, please fix pre-commit errors |
- Add file-level "# flake8: noqa: E402" to the three test files (imports
follow the sys.path.append("../common") adjustment), matching the existing
convention in L0_lifecycle/lifecycle_test.py.
- clang-format the out_of_range error string in http_server.cc to the 80-col style.
- Bump copyright year to 2026 on sagemaker_test.py and vertex_ai_test.py.
whoisj
approved these changes
Aug 17, 2026
yinggeh
approved these changes
Aug 18, 2026
Contributor
|
@pskiran1 Do we have a pipeline running? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does the PR do?
GetInferenceHeaderLengthparses theInference-Header-Content-Lengthrequestheader (and the SageMaker/Vertex
json-header-sizeMIME parameter) withstd::stoi.std::stoithrowsstd::out_of_rangefor values outside theintrange, but the three frontend implementations only caughtstd::invalid_argument. An uncaughtstd::out_of_rangeunwinds out of thehandler into the libevhtp C event loop, which has no C++ landing pad, so the
runtime calls
std::terminate()and the server process aborts.This applies the same
catch (const std::out_of_range&)pattern already used bythe sibling
GetContentLengthinhttp_server.cc, returning a 400 instead ofterminating. Fixed in all three HTTP frontends:
HTTPAPIServer::GetInferenceHeaderLength(src/http_server.cc)SagemakerAPIServer::GetInferenceHeaderLength+ its Content-Length parse (src/sagemaker_server.cc)VertexAiAPIServer::GetInferenceHeaderLength(src/vertex_ai_server.cc)Commit Type:
Where should the reviewer start?
src/http_server.cc— compare the newcatch (const std::out_of_range& oor)block in
GetInferenceHeaderLengthagainst the existing one in the siblingGetContentLength(same file); they now match.Test plan:
Added one regression test per frontend that sends a header value of
99999999999(exceeds INT_MAX) and asserts the server returns 400 and stayslive:
qa/L0_http/http_test.py::test_inference_header_content_length_out_of_rangeqa/L0_sagemaker/sagemaker_test.py::test_malformed_binary_header_out_of_rangeqa/L0_vertex_ai/vertex_ai_test.py::test_malformed_binary_header_out_of_rangeExpected unit-test counts in the corresponding
test.shharnesses were bumped(17 / 10 / 9). L0_http, L0_sagemaker and L0_vertex_ai all pass.
Caveats:
None. Change is limited to exception handling on an existing error path.
Background
Regression/incomplete-fix residual of CVE-2026-24210: the
out_of_rangecatchwas added to
GetContentLengthbut not to the threeGetInferenceHeaderLengthvariants when
std::atoiwas replaced withstd::stoi. Reported via internalsecurity tracking.
Related Issues: