From f06a0ee836ff738945292dc88a496b2aab9b6a57 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 7 Jun 2023 07:38:52 +0200 Subject: [PATCH] streaming/buffer: fix buf_offset getting out of sync During consolidation of regions, buf_offset could get out of sync if the region was grown on the left side. To fix, reset it and let "sbb slide" logic correct it. Bug: #6117. --- src/util-streaming-buffer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util-streaming-buffer.c b/src/util-streaming-buffer.c index 39147ebc1e..911504a1b3 100644 --- a/src/util-streaming-buffer.c +++ b/src/util-streaming-buffer.c @@ -1201,7 +1201,11 @@ static StreamingBufferRegion *BufferInsertAtRegionConsolidate(StreamingBuffer *s DEBUG_VALIDATE_BUG_ON(dst_size != dst->buf_size); if (dst_copy_offset != 0) memmove(dst->buf + dst_copy_offset, dst->buf, old_size); - dst->stream_offset = dst_offset; + if (dst_offset != dst->stream_offset) { + dst->stream_offset = dst_offset; + // buf_offset no longer valid, reset. + dst->buf_offset = 0; + } uint32_t new_offset = src_start->buf_offset; if (data_offset == src_start->stream_offset + src_start->buf_offset) {