Skip to content

Commit

Permalink
Fix potential division-by-zero
Browse files Browse the repository at this point in the history
This was found by the fuzzer added in
HdrHistogram#120

Signed-off-by: David Korczynski <david@adalogics.com>
  • Loading branch information
DavidKorczynski committed Jan 14, 2024
1 parent 8dcce8f commit efe50e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/hdr/hdr_histogram_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define HDR_TRAILING_ZEROS_INVALID -29992
#define HDR_VALUE_TRUNCATED -29991
#define HDR_ENCODED_INPUT_TOO_LONG -29990
#define HDR_INVALID_WORD_SIZE -29989

#define HDR_LOG_TAG_MAX_BUFFER_LEN (1024)

Expand Down
6 changes: 6 additions & 0 deletions src/hdr_histogram_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ const char* hdr_strerror(int errnum)
return "Truncated value found when decoding";
case HDR_ENCODED_INPUT_TOO_LONG:
return "The encoded input exceeds the size of the histogram";
case HDR_INVALID_WORD_SIZE:
return "Invalid word size";
default:
return strerror(errnum);
}
Expand Down Expand Up @@ -499,6 +501,10 @@ static int hdr_decode_compressed_v1(
}

word_size = word_size_from_cookie(be32toh(encoding_flyweight.cookie));
if (word_size == 0)
{
FAIL_AND_CLEANUP(cleanup, result, HDR_INVALID_WORD_SIZE);
}
counts_limit = be32toh(encoding_flyweight.payload_len) / word_size;
lowest_discernible_value = be64toh(encoding_flyweight.lowest_discernible_value);
highest_trackable_value = be64toh(encoding_flyweight.highest_trackable_value);
Expand Down

0 comments on commit efe50e3

Please sign in to comment.