Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions src/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,30 +603,21 @@ ReadDataFromJsonHelper(
break;
}
case TRITONSERVER_TYPE_BYTES: {
const char* cstr{nullptr};
size_t len{0};
const char* cstr;
size_t len = 0;
RETURN_IF_ERR(tensor_data.AsString(&cstr, &len));
if (len > INT64_MAX) {
return TRITONSERVER_ErrorNew(
TRITONSERVER_ERROR_INTERNAL,
"Unable to parse 'data' field: string length exceeds size"
" limitation");
}
// Quick sanity check to ensure we don't write beyond `expected_cnt`.
int64_t tmp_cnt = static_cast<int64_t>(*counter) +
static_cast<int64_t>(len) +
static_cast<int64_t>(sizeof(uint32_t));
if (tmp_cnt < 0 || tmp_cnt > expected_cnt) {
int32_t actual_cnt = *counter + len + sizeof(uint32_t);
if (actual_cnt < 0) {
return TRITONSERVER_ErrorNew(
TRITONSERVER_ERROR_INTERNAL,
"Shape does not match true shape of 'data' field");
"Unable to parse 'data' field: string length is negative");
}
if (tmp_cnt > INT32_MAX) {
if (static_cast<int64_t>(actual_cnt) > expected_cnt) {
return TRITONSERVER_ErrorNew(
TRITONSERVER_ERROR_INTERNAL,
"Unable to parse 'data' field: string length exceeds INT32_MAX");
"Shape does not match true shape of 'data' field");
}
int32_t actual_cnt = static_cast<int32_t>(tmp_cnt);
memcpy(
base + *counter, reinterpret_cast<char*>(&len), sizeof(uint32_t));
std::copy(cstr, cstr + len, base + *counter + sizeof(uint32_t));
Expand Down
Loading