Repository navigation
fix: return 400 for malformed option values - #1123
Merged
Merged
Conversation
A non-numeric value such as a JSON null reached std::stoll, whose bare "stoll" the server answered with 500. Option parse errors are now InvalidRequestError naming the option (HTTP 400, C API invalid argument), and an unsigned option no longer wraps " -1" to its maximum.
Owner
|
@ykhrustalev Thanks for the fix! Merged. |
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.
Problem
A non-numeric option value such as a JSON
null, which reaches the option parsers as the string"null", madestd::stoll/std::stofthrow a barestoll/stoferror that the server answered with HTTP 500 without naming the option. A 64-bit unsigned option such asseedalso accepted" -1"asUINT64_MAX.Solution
std::sto*calls inoptions.cppthrough aparse_numberhelper that throwsInvalidRequestErrornaming the option for non-numeric, out-of-range and trailing-garbage values.InvalidRequestErrorinstead ofstd::runtime_errorfrom the range, finite, positive, size and bool checks, so the server answers 400.-anywhere in an unsigned option value, not only a leading one.InvalidRequestErrortoAUDIOCPP_ERR_INVALID_ARGUMENTin the C API guard.cli_request_options_test, and makeslfm2_audio_session_testcheck that a malformedmax_tokenserror names the option.Testing
cli_request_options_test,audiocpp_c_api_path_testandlfm2_audio_session_testpass; the first two fail with theoptions.cppandaudiocpp.cppchanges reverted (the C API test also with onlyaudiocpp.cppreverted);ctesthas 0 failures (96 passed, 2 skipped for missing models).audiocpp_serverwith Silero VAD on CPU,POST /v1/tasks/run:threshold"abc"ornullandmin_speech_duration_ms99999999999return 400 naming the option (500 without the change);threshold0.5returns 200.audiocpp_cliwith Silero VAD on CPU:--session-option/--request-option threshold=abcand a--request-sequencewith"threshold": nullexit 1 withthreshold must be a float(without the change:stof: no conversion).