@@ -108,6 +108,45 @@ def test_high_expansion_prefix_without_output_buffer_limit():
108108 assert result == uncompressed
109109
110110
111+ def test_decompression_rejects_trailing_data ():
112+ data = brotlicffi .compress (b'A' * 100 ) + b'x'
113+ with pytest .raises (brotlicffi .error , match = 'trailing data' ):
114+ brotlicffi .decompress (data )
115+
116+
117+ @pytest .mark .parametrize ('method' , ['decompress' , 'process' ])
118+ @pytest .mark .parametrize ('output_buffer_limit' , [None , 50 ])
119+ def test_decompressobj_rejects_trailing_data (method , output_buffer_limit ):
120+ o = brotlicffi .Decompressor ()
121+ decompress = getattr (o , method )
122+ # Without a limit, decoding needs multiple internal buffer iterations.
123+ data = brotlicffi .compress (b'A' * 100 ) + b'tail'
124+ if output_buffer_limit is not None :
125+ assert decompress (data , output_buffer_limit = 50 ) == b'A' * 50
126+ assert not o .can_accept_more_data ()
127+ data = b''
128+
129+ with pytest .raises (brotlicffi .error , match = 'trailing data' ):
130+ decompress (data , output_buffer_limit = output_buffer_limit )
131+
132+ assert o ._unconsumed_data == b''
133+ with pytest .raises (brotlicffi .error , match = 'trailing data' ):
134+ decompress (b'x' , output_buffer_limit = output_buffer_limit )
135+
136+
137+ @pytest .mark .parametrize ('output_buffer_limit' , [None , 100 ])
138+ def test_decompressobj_rejects_data_after_finished (output_buffer_limit ):
139+ o = brotlicffi .Decompressor ()
140+ data = brotlicffi .compress (b'A' * 100 )
141+ assert (
142+ o .process (data , output_buffer_limit = output_buffer_limit ) == b'A' * 100
143+ )
144+ assert o .is_finished ()
145+
146+ with pytest .raises (brotlicffi .error , match = 'trailing data' ):
147+ o .process (b'x' , output_buffer_limit = output_buffer_limit )
148+
149+
111150def test_drip_feed (simple_compressed_file ):
112151 """
113152 Sending in the data one byte at a time still works.
0 commit comments