stou32() accepts partial parses, unlike the other stringutils converters
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu tại src/stringutils.cpp:112-129 và so sánh stou32 với stou64, stoi32 và stof. Mở rộng phạm vi kiểm thử hiện có của StringUtils.stou32 trong src/test/stringutils_test.cpp bằng các đầu vào số không đầy đủ, sau đó chạy các bài kiểm thử stringutils. Được xem là hoàn tất khi các ký tự không phải số ở cuối tạo ra std::nullopt, trong khi các trường hợp hiện có về giá trị âm, tràn số và giá trị lớn nhất vẫn hợp lệ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
ovms::stou32() accepts a string that is only partially a number, unlike every other converter in src/stringutils.cpp.
src/stringutils.cpp:112-129:
std::optional<uint32_t> stou32(const std::string& input) {
std::string str = input;
ovms::erase_spaces(str);
if (!str.empty() && str[0] == '-') {
return std::nullopt;
}
try {
uint64_t val = std::stoul(str); // no idx, no full-consumption check
if (val > std::numeric_limits<uint32_t>::max()) {
return std::nullopt;
}
return {static_cast<uint32_t>(val)};
} catch (...) {
return std::nullopt;
}
}
std::stoul stops at the first character it cannot use and still reports success. Its siblings in the same file all guard against that by passing &idx and comparing against the length:
stou64—src/stringutils.cpp:143-147stoi32—src/stringutils.cpp:161-165stof—src/stringutils.cpp:203-206
(stoi64 at :181-185 validates by scanning digits first, which is equivalent.) stou32 is the only one without the check, so:
12abc -> 12
3.9 -> 3
0x10 -> 0
100% -> 100
Call sites affected
-
src/grpcservermodule.cpp:79— theGRPC_SERVERSenvironment variable:const char* environmentVariableBuffer = std::getenv("GRPC_SERVERS"); if (environmentVariableBuffer) { auto result = stou32(environmentVariableBuffer); if (result && result.value() > 0) { return result.value(); } }GRPC_SERVERS=4xsilently starts 4 gRPC servers instead of being rejected and falling back toconfig.grpcWorkers(). A typo in a deployment environment variable is applied rather than reported. -
src/audio/speech_to_text/s2t_servable.cpp:81— the transcriptiontemperaturefield, used as a fallback afterovms::stofhas already rejected the value. That endpoint's user-visible symptom is filed separately; either fix resolves it independently and the two do not conflict.
To Reproduce
Unit level, alongside the existing StringUtils.stou32 case:
EXPECT_FALSE(ovms::stou32("12abc")); // currently returns 12
EXPECT_FALSE(ovms::stou32("3.9")); // currently returns 3
EXPECT_FALSE(ovms::stou32("0x10")); // currently returns 0
End to end:
GRPC_SERVERS=4x ovms --model_path /models/... --model_name m --port 9000
# starts 4 gRPC servers; expected: the value is rejected and grpcWorkers() is used
Expected behavior
stou32 behaves like stou64/stoi32/stof: a string that is not entirely a number returns std::nullopt.
Logs
None — the value is accepted, so nothing is logged.
Configuration
- OVMS version:
main@fadb3314 - Any configuration; reachable via the
GRPC_SERVERSenvironment variable - CPU
- N/A
- N/A
Additional context
Suggested fix, matching the siblings:
size_t idx = 0;
uint64_t val = std::stoul(str, &idx);
if (idx != str.size()) {
return std::nullopt;
}
The existing StringUtils.stou32 test covers only a negative value, overflow and the maximum, so none of it changes.
Separate, deliberately not bundled: stou32 calls erase_spaces() on its input first, so stou32("12 34") yields 1234 both before and after such a fix, whereas stou64 rejects " 100 " outright (there is an explicit test for that at src/test/stringutils_test.cpp:218). Whether stou32 should also stop erasing interior whitespace is a separate behavioural question and worth deciding on its own.
Also same class, different function, mentioned only so it is on the record: src/grpcservermodule.cpp:143 uses a bare std::stoi(value) to decide whether a gRPC channel argument is an integer, so grpc.max_receive_message_length=4MB is passed to gRPC as the integer 4 rather than as the string it is. That may well be intended, given the surrounding comment, so I have not touched it.
I have a patch for this and will open a PR shortly.
- Ngôn ngữ chính
- C++
- Star
- 952
- Fork
- 285
- Merge trung bình
- 3 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 45
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openvinotoolkit/model_server
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
openvinotoolkit/model_server#4703 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Feature Request: /v1/decisions endpoint for structured single-token classification (vLLM/OpenAI-compatible)Có thể đã có người làm @sergey-zinchenko đã nhận 7 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 1/100
openvinotoolkit/model_server#4701 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
KServe REST parser drops requested outputs except the lastCó thể đã có người làm @YugShah1510 đã nhận 6 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
openvinotoolkit/model_server#4690 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
KServe REST rejects INT64 and UINT64 values outside 32-bit rangeCó thể đã có người làm @YugShah1510 đã nhận 6 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
openvinotoolkit/model_server#4688 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Preserve double precision when parsing FP64 REST inputsCó thể đã có người làm @YugShah1510 đã nhận 6 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
openvinotoolkit/model_server#4686 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của openvinotoolkit/model_server
Issue tương tự
-
backlog documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
EchoTools/nevr-runtime#1328 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Component - Build
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Description of the bugĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
HarbourMasters/Lighthouse#655 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug-unconfirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
wazuh/wazuh#40870 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày