Clamp 32-bit varints to 5 bytes to fix a fuzz failure.

pull/13171/head
Joshua Haberman 4 years ago
parent 50a543de7f
commit 9abf8e043f
  1. 4
      benchmarks/compare.py
  2. 17
      upb/decode.c

@ -45,7 +45,9 @@ def Benchmark(outbase, bench_cpu=True, runs=12, fasttable=False):
# Translate into the format expected by benchstat.
with open(outbase + ".txt", "w") as f:
for run in bench_json["benchmarks"]:
name = re.sub(r'^BM_', 'Benchmark', run["name"])
name = run["name"]
name = name.replace(" ", "")
name = re.sub(r'^BM_', 'Benchmark', name)
if name.endswith("_mean") or name.endswith("_median") or name.endswith("_stddev"):
continue
values = (name, run["iterations"], run["cpu_time"])

@ -221,11 +221,18 @@ static const char *decode_varint64(upb_decstate *d, const char *ptr,
UPB_FORCEINLINE
static const char *decode_varint32(upb_decstate *d, const char *ptr,
uint32_t *val) {
uint64_t u64;
ptr = decode_varint64(d, ptr, &u64);
if (u64 > UINT32_MAX) decode_err(d);
*val = (uint32_t)u64;
return ptr;
uint64_t byte = (uint8_t)*ptr;
if (UPB_LIKELY((byte & 0x80) == 0)) {
*val = byte;
return ptr + 1;
} else {
const char *start = ptr;
decode_vret res = decode_longvarint64(ptr, byte);
ptr = res.ptr;
*val = res.val;
if (!ptr || *val > UINT32_MAX || ptr - start > 5) decode_err(d);
return ptr;
}
}
static void decode_munge(int type, wireval *val) {

Loading…
Cancel
Save