Rework bytes size check (#547)

The previous check was prone to giving warnings on various platforms.
Also there is no real need to check for other than PB_ATYPE_STATIC, as
anyone passing a pointer variable is responsible for having correctly
allocated the array.
This commit is contained in:
Petteri Aimonen committed 2020-06-23 13:28:21 +03:00
1 parent 6801500e23
commit 69e02afb6e
1 file changed
+2 -2
+2 -2
View File
@@ -842,8 +842,8 @@ static bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_iter_t
return pb_encode_string(stream, NULL, 0);
}
if ((size_t)bytes->size > ((size_t)-1) - offsetof(pb_bytes_array_t, bytes) ||
(PB_ATYPE(field->type) == PB_ATYPE_STATIC && PB_BYTES_ARRAY_T_ALLOCSIZE(bytes->size) > field->data_size))
if (PB_ATYPE(field->type) == PB_ATYPE_STATIC &&
bytes->size > field->data_size - offsetof(pb_bytes_array_t, bytes))
{
PB_RETURN_ERROR(stream, "bytes size exceeded");
}