Skip to content

Commit 815fefb

Browse files
whoisjyinggeh
andcommitted
Add Integer Overflow Sanity Check
This change adds a sanity check prior to a static cast of `int32_t` to `int64_t` to use as an offset. While the current code cannot enter this state, this protects against future changes. Co-authored-by: Yingge He <157551214+yinggeh@users.noreply.github.com>
1 parent 0eb1f23 commit 815fefb

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/http_server.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,14 @@ ReadDataFromJsonHelper(
606606
const char* cstr;
607607
size_t len = 0;
608608
RETURN_IF_ERR(tensor_data.AsString(&cstr, &len));
609-
if (static_cast<int64_t>(*counter + len + sizeof(uint32_t)) >
610-
expected_cnt) {
609+
// Quick sanity check to ensure we don't write beyond `expected_cnt`.
610+
int32_t actual_cnt = *counter + len + sizeof(uint32_t);
611+
if (actual_cnt < 0) {
612+
return TRITONSERVER_ErrorNew(
613+
TRITONSERVER_ERROR_INTERNAL,
614+
"Unable to parse 'data' field: string length is negative");
615+
}
616+
if (static_cast<int64_t>(actual_cnt) > expected_cnt) {
611617
return TRITONSERVER_ErrorNew(
612618
TRITONSERVER_ERROR_INTERNAL,
613619
"Shape does not match true shape of 'data' field");

0 commit comments

Comments
 (0)