Skip to content

Commit

Permalink
Rework bytes size check (#547)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
PetteriAimonen committed Jun 23, 2020
1 parent 6801500 commit 69e02af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pb_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 69e02af

Please sign in to comment.