diff --git a/src/http_server.cc b/src/http_server.cc index b0e5ef7902..86707899f3 100644 --- a/src/http_server.cc +++ b/src/http_server.cc @@ -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(*counter) + - static_cast(len) + - static_cast(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(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(tmp_cnt); memcpy( base + *counter, reinterpret_cast(&len), sizeof(uint32_t)); std::copy(cstr, cstr + len, base + *counter + sizeof(uint32_t));