@@ -603,30 +603,21 @@ ReadDataFromJsonHelper(
603603 break ;
604604 }
605605 case TRITONSERVER_TYPE_BYTES : {
606- const char * cstr{ nullptr } ;
607- size_t len{ 0 } ;
606+ const char * cstr;
607+ size_t len = 0 ;
608608 RETURN_IF_ERR (tensor_data.AsString (&cstr, &len));
609- if (len > INT64_MAX ) {
610- return TRITONSERVER_ErrorNew (
611- TRITONSERVER_ERROR_INTERNAL ,
612- " Unable to parse 'data' field: string length exceeds size"
613- " limitation" );
614- }
615609 // Quick sanity check to ensure we don't write beyond `expected_cnt`.
616- int64_t tmp_cnt = static_cast <int64_t >(*counter) +
617- static_cast <int64_t >(len) +
618- static_cast <int64_t >(sizeof (uint32_t ));
619- if (tmp_cnt < 0 || tmp_cnt > expected_cnt) {
610+ int32_t actual_cnt = *counter + len + sizeof (uint32_t );
611+ if (actual_cnt < 0 ) {
620612 return TRITONSERVER_ErrorNew (
621613 TRITONSERVER_ERROR_INTERNAL ,
622- " Shape does not match true shape of 'data' field" );
614+ " Unable to parse 'data' field: string length is negative " );
623615 }
624- if (tmp_cnt > INT32_MAX ) {
616+ if (static_cast < int64_t >(actual_cnt) > expected_cnt ) {
625617 return TRITONSERVER_ErrorNew (
626618 TRITONSERVER_ERROR_INTERNAL ,
627- " Unable to parse 'data' field: string length exceeds INT32_MAX " );
619+ " Shape does not match true shape of 'data' field " );
628620 }
629- int32_t actual_cnt = static_cast <int32_t >(tmp_cnt);
630621 memcpy (
631622 base + *counter, reinterpret_cast <char *>(&len), sizeof (uint32_t ));
632623 std::copy (cstr, cstr + len, base + *counter + sizeof (uint32_t ));
0 commit comments