Skip to content

Commit fdb9018

Browse files
Internal change
PiperOrigin-RevId: 736203959
1 parent a6e6789 commit fdb9018

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

upb/mini_descriptor/decode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ static void upb_MtDecoder_ParseMessage(upb_MtDecoder* d, const char* data,
495495
size_t len) {
496496
// Buffer length is an upper bound on the number of fields. We will return
497497
// what we don't use.
498+
if (SIZE_MAX / sizeof(*d->fields) < len) {
499+
upb_MdDecoder_ErrorJmp(&d->base, "Out of memory");
500+
}
498501
d->fields = upb_Arena_Malloc(d->arena, sizeof(*d->fields) * len);
499502
upb_MdDecoder_CheckOutOfMemory(&d->base, d->fields);
500503

upb/reflection/enum_value_def.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
#include "upb/reflection/internal/enum_value_def.h"
99

10+
#include <stddef.h>
1011
#include <stdint.h>
12+
#include <stdlib.h>
1113

14+
#include "upb/base/string_view.h"
15+
#include "upb/mem/arena.h"
16+
#include "upb/reflection/def.h"
1217
#include "upb/reflection/def_type.h"
1318
#include "upb/reflection/enum_def.h"
1419
#include "upb/reflection/enum_value_def.h"
15-
#include "upb/reflection/file_def.h"
1620
#include "upb/reflection/internal/def_builder.h"
1721
#include "upb/reflection/internal/enum_def.h"
1822

@@ -41,7 +45,8 @@ static int _upb_EnumValueDef_Compare(const void* p1, const void* p2) {
4145
}
4246

4347
const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v,
44-
int n, upb_Arena* a) {
48+
size_t n, upb_Arena* a) {
49+
if (SIZE_MAX / sizeof(void*) < n) return NULL;
4550
// TODO: Try to replace this arena alloc with a persistent scratch buffer.
4651
upb_EnumValueDef** out =
4752
(upb_EnumValueDef**)upb_Arena_Malloc(a, n * sizeof(void*));

upb/reflection/internal/enum_value_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ upb_EnumValueDef* _upb_EnumValueDefs_New(
2727
bool* is_sorted);
2828

2929
const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v,
30-
int n, upb_Arena* a);
30+
size_t n, upb_Arena* a);
3131

3232
#ifdef __cplusplus
3333
} /* extern "C" */

0 commit comments

Comments
 (0)