Tokenize endpoint empty array crash fix #4208
Open
przepeck wants to merge 7 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the tokenize request parser when the text field contains an empty nested array (e.g. {"text":[[]]}), by explicitly rejecting empty inner arrays and adding regression tests across tokenize endpoint test suites.
Changes:
- Add an explicit guard in
TokenizeParser::parseInput()to reject empty inner arrays before indexingarray[0]. - Add negative HTTP tests to ensure
textwith empty nested arrays returns an error (and does not crash) for embeddings, rerank, and LLM tokenize endpoints. - Remove a previously existing
GTEST_SKIP()in the LLM tokenize “add_special_tokens” test for VLM models.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/tokenize/tokenize_parser.cpp |
Adds empty-inner-array validation to prevent out-of-bounds access when inspecting nested arrays. |
src/test/reranknode_test.cpp |
Adds HTTP regression tests covering empty nested arrays for the rerank tokenize endpoint. |
src/test/llm/tokenize_endpoint_test.cpp |
Adds HTTP regression tests for empty nested arrays across all LLM tokenize test parameters; also removes a VLM-specific skip for add_special_tokens. |
src/test/embeddingsnode_test.cpp |
Adds HTTP regression tests covering empty nested arrays for the embeddings tokenize endpoint. |
Comment on lines
418
to
421
| TEST_P(LLMTokenizeTests, tokenizeStringWithAddSpecialTokens) { | ||
| auto params = GetParam(); | ||
| if (params.modelName == "vlm_cb_regular" || params.modelName == "vlm_legacy_regular") { | ||
| GTEST_SKIP() << "Skipping test for " << params.modelName; | ||
| } | ||
|
|
||
| std::string requestBody = R"( |
Comment on lines
+790
to
+798
| TEST_F(EmbeddingsTokenizeHttpTest, tokenizeEmptyNestedArray) { | ||
| std::string requestBody = R"( | ||
| { | ||
| "model": "embeddings_ov", | ||
| "text": [[]] | ||
| } | ||
| )"; | ||
| Status status = handler->dispatchToProcessor(endpointTokenize, requestBody, &response, comp, responseComponents, writer, multiPartParser); | ||
| ASSERT_EQ(status, ovms::StatusCode::MEDIAPIPE_EXECUTION_ERROR) << status.string(); |
Comment on lines
+609
to
+617
| TEST_F(RerankTokenizeHttpTest, tokenizeEmptyNestedArray) { | ||
| std::string requestBody = R"( | ||
| { | ||
| "model": "rerank_ov", | ||
| "text": [[]] | ||
| } | ||
| )"; | ||
| Status status = handler->dispatchToProcessor(endpointTokenize, requestBody, &response, comp, responseComponents, writer, multiPartParser); | ||
| ASSERT_EQ(status, ovms::StatusCode::MEDIAPIPE_EXECUTION_ERROR) << status.string(); |
Comment on lines
+443
to
+455
| TEST_P(LLMTokenizeTests, tokenizeEmptyNestedArray) { | ||
| auto params = GetParam(); | ||
|
|
||
| std::string requestBody = R"( | ||
| { | ||
| "model": ")" + params.modelName + | ||
| R"(", | ||
| "text": [[]] | ||
| } | ||
| )"; | ||
| Status status = handler->dispatchToProcessor(endpointTokenize, requestBody, &response, comp, responseComponents, writer, multiPartParser); | ||
| ASSERT_EQ(status, ovms::StatusCode::MEDIAPIPE_EXECUTION_ERROR) << status.string(); | ||
| } |
michalkulakowski
approved these changes
May 14, 2026
dkalinowski
reviewed
May 14, 2026
| TEST_P(LLMTokenizeTests, tokenizeStringWithAddSpecialTokens) { | ||
| auto params = GetParam(); | ||
| if (params.modelName == "vlm_cb_regular" || params.modelName == "vlm_legacy_regular") { | ||
| GTEST_SKIP() << "Skipping test for " << params.modelName; |
Collaborator
There was a problem hiding this comment.
Is it working for all paths, or only special token path? Do other tests have it unskipped?
dkalinowski
approved these changes
May 14, 2026
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.
🛠 Summary
CVS-186166
Adding checks for empty nested array, which was making OVMS crash
🧪 Checklist
``