epan: Handle subset tvbuffs with non-zero offets and length -1

According to tvbuff.h, tvb_new_subset_length() with length -1
should behave like tvb_new_subset_remaining(). That means that
the reported length should subtract off the offset into the
original tvb.
This commit is contained in:
John Thacker 2022-08-20 13:25:06 -04:00 committed by A Wireshark GitLab Utility
parent 58907c0723
commit ccf720d95d
1 changed files with 10 additions and 0 deletions

View File

@ -211,6 +211,16 @@ tvb_new_subset_length(tvbuff_t *backing, const gint backing_offset, const gint r
&subset_tvb_offset,
&subset_tvb_length);
/*
* If the requested reported length is "to the end of the buffer",
* subtract the offset from the total length. We do this now, because
* the user might have passed in a negative offset.
*/
if (reported_length == -1) {
THROW_ON(backing->reported_length < subset_tvb_offset, ReportedBoundsError);
actual_reported_length -= subset_tvb_offset;
}
tvb = tvb_new_with_subset(backing, (guint)actual_reported_length,
subset_tvb_offset, subset_tvb_length);