Skip to content

Commit defa273

Browse files
habermancopybara-github
authored andcommitted
Fixed ubsan error by always treating field number as uint32_t.
The previous error was: ``` third_party/upb/upb/wire/decode.c:1132:68: runtime error: left shift of 283231142 by 3 places cannot be represented in type 'int' ``` PiperOrigin-RevId: 841908347
1 parent 6dea711 commit defa273

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

upb/wire/decode.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ static upb_MiniTableField upb_Decoder_FieldNotFoundField = {
807807

808808
UPB_NOINLINE const upb_MiniTableField* _upb_Decoder_FindExtensionField(
809809
upb_Decoder* d, const upb_MiniTable* t, uint32_t field_number, int ext_mode,
810-
int wire_type) {
810+
uint32_t wire_type) {
811811
// Treat a message set as an extendable message if it is a delimited field.
812812
// This provides compatibility with encoders that are unaware of message
813813
// sets and serialize them as normal extensions.
@@ -830,7 +830,7 @@ UPB_NOINLINE const upb_MiniTableField* _upb_Decoder_FindExtensionField(
830830
static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d,
831831
const upb_MiniTable* t,
832832
uint32_t field_number,
833-
int wire_type) {
833+
uint32_t wire_type) {
834834
UPB_ASSERT(t);
835835
const upb_MiniTableField* field =
836836
upb_MiniTable_FindFieldByNumber(t, field_number);
@@ -969,7 +969,8 @@ UPB_FORCEINLINE
969969
const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
970970
const upb_MiniTable* mt,
971971
const upb_MiniTableField* field,
972-
int wire_type, wireval* val, int* op) {
972+
uint32_t wire_type, wireval* val,
973+
int* op) {
973974
static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) |
974975
(1 << kUpb_FieldType_Fixed32) |
975976
(1 << kUpb_FieldType_SFixed32);
@@ -1059,8 +1060,8 @@ const char* _upb_Decoder_DecodeKnownField(upb_Decoder* d, const char* ptr,
10591060
}
10601061

10611062
static const char* _upb_Decoder_FindFieldStart(upb_Decoder* d, const char* ptr,
1062-
int field_number,
1063-
int wire_type) {
1063+
uint32_t field_number,
1064+
uint32_t wire_type) {
10641065
// Since unknown fields are the uncommon case, we do a little extra work here
10651066
// to walk backwards through the buffer to find the field start. This frees
10661067
// up a register in the fast paths (when the field is known), which leads to
@@ -1109,11 +1110,9 @@ static const char* _upb_Decoder_FindFieldStart(upb_Decoder* d, const char* ptr,
11091110
return start;
11101111
}
11111112

1112-
static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d,
1113-
const char* ptr,
1114-
upb_Message* msg,
1115-
int field_number,
1116-
int wire_type, wireval val) {
1113+
static const char* _upb_Decoder_DecodeUnknownField(
1114+
upb_Decoder* d, const char* ptr, upb_Message* msg, uint32_t field_number,
1115+
uint32_t wire_type, wireval val) {
11171116
if (field_number == 0) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
11181117

11191118
const char* start =
@@ -1159,7 +1158,8 @@ static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d,
11591158

11601159
UPB_FORCEINLINE
11611160
const char* _upb_Decoder_DecodeFieldTag(upb_Decoder* d, const char* ptr,
1162-
int* field_number, int* wire_type) {
1161+
uint32_t* field_number,
1162+
uint32_t* wire_type) {
11631163
#ifndef NDEBUG
11641164
d->debug_tagstart = ptr;
11651165
#endif
@@ -1176,7 +1176,8 @@ UPB_FORCEINLINE
11761176
const char* _upb_Decoder_DecodeFieldData(upb_Decoder* d, const char* ptr,
11771177
upb_Message* msg,
11781178
const upb_MiniTable* mt,
1179-
int field_number, int wire_type) {
1179+
uint32_t field_number,
1180+
uint32_t wire_type) {
11801181
#ifndef NDEBUG
11811182
d->debug_valstart = ptr;
11821183
#endif
@@ -1212,8 +1213,8 @@ UPB_FORCEINLINE
12121213
const char* _upb_Decoder_DecodeFieldNoFast(upb_Decoder* d, const char* ptr,
12131214
upb_Message* msg,
12141215
const upb_MiniTable* mt) {
1215-
int field_number;
1216-
int wire_type;
1216+
uint32_t field_number;
1217+
uint32_t wire_type;
12171218

12181219
ptr = _upb_Decoder_DecodeFieldTag(d, ptr, &field_number, &wire_type);
12191220

0 commit comments

Comments
 (0)