File tree 2 files changed +44
-1
lines changed
2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test `xzdecode` simple case
3
+ --SKIPIF--
4
+ <?php
5
+ if (!extension_loaded ("xz " )) {
6
+ print ("XZ extension is not loaded! " );
7
+ }
8
+ ?>
9
+ --FILE--
10
+ <?php
11
+
12
+ $ str = file_get_contents (__FILE__ );
13
+
14
+ $ encoded = xzencode ($ str );
15
+ print ("encoding finished \n" );
16
+ $ decoded = xzdecode ($ encoded );
17
+ print ("decoding finished \n" );
18
+ var_dump ($ str === $ decoded );
19
+
20
+ print ("empty string \n" );
21
+ var_dump (xzdecode ("" ));
22
+ print ("garbage \n" );
23
+ var_dump (xzdecode ("this is not XZ data " ));
24
+ ?>
25
+ --EXPECT--
26
+ encoding finished
27
+ decoding finished
28
+ bool(true)
29
+ empty string
30
+ bool(false)
31
+ garbage
32
+ bool(false)
Original file line number Diff line number Diff line change @@ -273,6 +273,10 @@ PHP_FUNCTION(xzdecode)
273
273
return ;
274
274
}
275
275
276
+ if (!in_len ) {
277
+ RETURN_BOOL (0 ); /* empty string is not xz data */
278
+ }
279
+
276
280
/* The output string (encoded). */
277
281
uint8_t * out = NULL ;
278
282
/* The length of the output string. */
@@ -300,6 +304,14 @@ PHP_FUNCTION(xzdecode)
300
304
lzma_ret status = LZMA_OK ;
301
305
while (strm .avail_in != 0 ) {
302
306
status = lzma_code (& strm , LZMA_RUN );
307
+ if (status != LZMA_OK && status != LZMA_STREAM_END ) {
308
+ if (out ) {
309
+ efree (out );
310
+ }
311
+ lzma_end (& strm );
312
+ RETURN_BOOL (0 ); /* probably not xz data */
313
+ }
314
+
303
315
/* More memory is required. */
304
316
if (strm .avail_out == 0 ) {
305
317
out = memmerge (out , buff , out_len , XZ_BUFFER_SIZE );
@@ -308,7 +320,6 @@ PHP_FUNCTION(xzdecode)
308
320
strm .next_out = buff ;
309
321
}
310
322
}
311
- (void )status ; // avoid -Wunused-but-set-variable warning
312
323
/* Merging last fragment. */
313
324
out = memmerge (out , buff , out_len , XZ_BUFFER_SIZE - strm .avail_out );
314
325
out_len += XZ_BUFFER_SIZE - strm .avail_out ;
You can’t perform that action at this time.
0 commit comments