Skip to content

Handling correctly negative values in /v3/tokenize endpoint#4324

Open
przepeck wants to merge 2 commits into
mainfrom
przepeck/tokenize_max_len_negative
Open

Handling correctly negative values in /v3/tokenize endpoint#4324
przepeck wants to merge 2 commits into
mainfrom
przepeck/tokenize_max_len_negative

Conversation

@przepeck

Copy link
Copy Markdown
Collaborator

🛠 Summary

CVS-189517
Changing handling of negative values of max_length parameter.

🧪 Checklist

  • Unit tests added.
  • The documentation updated.
  • Change follows security best practices.
    ``

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the /v3/tokenize request parsing so that negative values for the max_length parameter are rejected (avoiding the previous signed-to-size_t conversion behavior) and adds coverage for this case.

Changes:

  • Parse max_length only as an unsigned integer and update the associated validation error string.
  • Update existing unit test expectations for the new error message.
  • Add a unit test that verifies negative max_length is rejected.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/tokenize/tokenize_parser.cpp Tightens max_length validation to unsigned-only and updates the error message.
src/test/tokenize_parser_test.cpp Updates the expected error message and adds a negative-max_length test case.

Comment on lines +84 to 88
if (it->value.IsUint()) {
size_t max_length = it->value.GetUint();
request.parameters["max_length"] = max_length;
// Keep OVMS tokenize API contract: max_length implies truncation.
request.parameters["truncation"] = true;
if (it != parsedJson.MemberEnd()) {
if (it->value.IsInt()) {
size_t max_length = it->value.GetInt();
if (it->value.IsUint()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is zero allowed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes, I will add additional condition for 0

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.

4 participants