Skip to content

Commit 133e074

Browse files
DavidKorczynskimikeb01
authored andcommitted
Fix potential division-by-zero
This was found by the fuzzer added in #120 Signed-off-by: David Korczynski <[email protected]>
1 parent 8dcce8f commit 133e074

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

include/hdr/hdr_histogram_log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define HDR_TRAILING_ZEROS_INVALID -29992
2121
#define HDR_VALUE_TRUNCATED -29991
2222
#define HDR_ENCODED_INPUT_TOO_LONG -29990
23+
#define HDR_INVALID_WORD_SIZE -29989
2324

2425
#define HDR_LOG_TAG_MAX_BUFFER_LEN (1024)
2526

src/hdr_histogram_log.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ const char* hdr_strerror(int errnum)
101101
return "Truncated value found when decoding";
102102
case HDR_ENCODED_INPUT_TOO_LONG:
103103
return "The encoded input exceeds the size of the histogram";
104+
case HDR_INVALID_WORD_SIZE:
105+
return "Invalid word size";
104106
default:
105107
return strerror(errnum);
106108
}
@@ -499,6 +501,10 @@ static int hdr_decode_compressed_v1(
499501
}
500502

501503
word_size = word_size_from_cookie(be32toh(encoding_flyweight.cookie));
504+
if (word_size == 0)
505+
{
506+
FAIL_AND_CLEANUP(cleanup, result, HDR_INVALID_WORD_SIZE);
507+
}
502508
counts_limit = be32toh(encoding_flyweight.payload_len) / word_size;
503509
lowest_discernible_value = be64toh(encoding_flyweight.lowest_discernible_value);
504510
highest_trackable_value = be64toh(encoding_flyweight.highest_trackable_value);

0 commit comments

Comments
 (0)