Skip to content

Commit 19f9111

Browse files
committed
compressable: fix RuntimeError with large zstd compressed data
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent c5cf521 commit 19f9111

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/fluent/plugin/compressable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ def string_decompress_gzip(compressed_data)
7979

8080
def string_decompress_zstd(compressed_data)
8181
io = StringIO.new(compressed_data)
82+
reader = Zstd::StreamReader.new(io)
8283
out = ''
8384
loop do
84-
reader = Zstd::StreamReader.new(io)
8585
# Zstd::StreamReader needs to specify the size of the buffer
8686
out << reader.read(1024)
8787
# Zstd::StreamReader doesn't provide unused data, so we have to manually adjust the position

test/plugin/test_compressable.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,14 @@ def compress_assert_equal(expected, actual)
8383
assert_equal '', decompress('')
8484
assert_equal '', decompress('', output_io: StringIO.new)
8585
end
86+
87+
test 'decompress large zstd compressed data' do
88+
src1 = SecureRandom.random_bytes(1024)
89+
src2 = SecureRandom.random_bytes(1024)
90+
src3 = SecureRandom.random_bytes(1024)
91+
92+
zstd_compressed_data = compress(src1, type: :zstd) + compress(src2, type: :zstd) + compress(src3, type: :zstd)
93+
assert_equal src1 + src2 + src3, decompress(zstd_compressed_data, type: :zstd)
94+
end
8695
end
8796
end

0 commit comments

Comments
 (0)