Check array max size when encoding.

Update issue 90
Status: FixedInGit
This commit is contained in:
Petteri Aimonen
2013-10-20 21:42:00 +03:00
parent 388d4de833
commit e83fbd18d3
2 changed files with 17 additions and 0 deletions

View File

@@ -94,6 +94,9 @@ static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *fie
if (count == 0) if (count == 0)
return true; return true;
if (count > field->array_size)
PB_RETURN_ERROR(stream, "array max size exceeded");
/* We always pack arrays if the datatype allows it. */ /* We always pack arrays if the datatype allows it. */
if (PB_LTYPE(field->type) <= PB_LTYPE_LAST_PACKABLE) if (PB_LTYPE(field->type) <= PB_LTYPE_LAST_PACKABLE)

View File

@@ -223,6 +223,20 @@ int main()
TEST(!pb_encode(&s, FloatArray_fields, &msg)) TEST(!pb_encode(&s, FloatArray_fields, &msg))
} }
{
uint8_t buffer[50];
pb_ostream_t s;
FloatArray msg = {1, {99.0f}};
COMMENT("Test array size limit in pb_encode")
s = pb_ostream_from_buffer(buffer, sizeof(buffer));
TEST((msg.data_count = 10) && pb_encode(&s, FloatArray_fields, &msg))
s = pb_ostream_from_buffer(buffer, sizeof(buffer));
TEST((msg.data_count = 11) && !pb_encode(&s, FloatArray_fields, &msg))
}
{ {
uint8_t buffer[10]; uint8_t buffer[10];
pb_ostream_t s; pb_ostream_t s;