From ed564186e14c79c767096f4b306dc3c6c5bd2e7d Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Thu, 24 Oct 2013 21:45:39 +0300 Subject: Detect invalid sizes when encoding bytes fields. --- pb_encode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pb_encode.c') diff --git a/pb_encode.c b/pb_encode.c index 4aced3cb..563c1bb7 100644 --- a/pb_encode.c +++ b/pb_encode.c @@ -521,7 +521,10 @@ bool checkreturn pb_enc_fixed32(pb_ostream_t *stream, const pb_field_t *field, c bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src) { const pb_bytes_array_t *bytes = (const pb_bytes_array_t*)src; - UNUSED(field); + + if (bytes->size + offsetof(pb_bytes_array_t, bytes) > field->data_size) + PB_RETURN_ERROR(stream, "bytes size exceeded"); + return pb_encode_string(stream, bytes->bytes, bytes->size); } -- cgit 1.2.3-korg