Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hdr_histogram_log: Fix potential division-by-zero #121

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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