@@ -31,7 +31,9 @@ Module Name:
3131#include "minlzlib.h"
3232#include "xzstream.h"
3333
34- void __security_check_cookie (uintptr_t _StackCookie ) { (void )(_StackCookie ); }
34+ #ifdef _WIN32
35+ void __security_check_cookie (_In_ uintptr_t _StackCookie ) { (void )(_StackCookie ); }
36+ #endif
3537
3638#ifdef MINLZ_META_CHECKS
3739//
@@ -210,9 +212,9 @@ XzDecodeStreamFooter (
210212 //
211213 // Validate no flags other than checksum type are set
212214 //
213- if ((streamFooter -> Flags != 0 ) &&
214- ((streamFooter -> CheckType != XzCheckTypeCrc32 ) &&
215- (streamFooter -> CheckType != XzCheckTypeNone )))
215+ if ((streamFooter -> u . Flags != 0 ) &&
216+ ((streamFooter -> u . s . CheckType != XzCheckTypeCrc32 ) &&
217+ (streamFooter -> u . s . CheckType != XzCheckTypeNone )))
216218 {
217219 return false;
218220 }
@@ -230,7 +232,7 @@ XzDecodeStreamFooter (
230232 //
231233 if (Crc32 (& streamFooter -> BackwardSize ,
232234 sizeof (streamFooter -> BackwardSize ) +
233- sizeof (streamFooter -> Flags )) !=
235+ sizeof (streamFooter -> u . Flags )) !=
234236 streamFooter -> Crc32 )
235237 {
236238 return false;
@@ -327,23 +329,23 @@ XzDecodeStreamHeader (
327329 //
328330 // Validate no flags other than checksum type are set
329331 //
330- if ((streamHeader -> Flags != 0 ) &&
331- ((streamHeader -> CheckType != XzCheckTypeCrc32 ) &&
332- (streamHeader -> CheckType != XzCheckTypeNone )))
332+ if ((streamHeader -> u . Flags != 0 ) &&
333+ ((streamHeader -> u . s . CheckType != XzCheckTypeCrc32 ) &&
334+ (streamHeader -> u . s . CheckType != XzCheckTypeNone )))
333335 {
334336 return false;
335337 }
336338
337339 //
338340 // Remember that a checksum might come at the end of the block later
339341 //
340- Container .ChecksumSize = streamHeader -> CheckType * 4 ;
342+ Container .ChecksumSize = streamHeader -> u . s . CheckType * 4 ;
341343#endif
342344#ifdef MINLZ_INTEGRITY_CHECKS
343345 //
344346 // Compute the header's CRC32 and make sure it's not corrupted
345347 //
346- if (Crc32 (& streamHeader -> Flags , sizeof (streamHeader -> Flags )) !=
348+ if (Crc32 (& streamHeader -> u . Flags , sizeof (streamHeader -> u . Flags )) !=
347349 streamHeader -> Crc32 )
348350 {
349351 return false;
@@ -354,7 +356,7 @@ XzDecodeStreamHeader (
354356
355357bool
356358XzDecodeBlockHeader (
357- uint32_t OutputSize
359+ void
358360 )
359361{
360362 PXZ_BLOCK_HEADER blockHeader ;
@@ -381,7 +383,7 @@ XzDecodeBlockHeader (
381383 //
382384 // Validate that no additional flags or filters are enabled
383385 //
384- if (blockHeader -> Flags != 0 )
386+ if (blockHeader -> u . Flags != 0 )
385387 {
386388 return false;
387389 }
@@ -397,31 +399,29 @@ XzDecodeBlockHeader (
397399 //
398400 // With the expected number of property bytes
399401 //
400- if (blockHeader -> LzmaFlags .Size != sizeof (blockHeader -> LzmaFlags .Properties ))
402+ if (blockHeader -> LzmaFlags .Size != sizeof (blockHeader -> LzmaFlags .u . Properties ))
401403 {
402404 return false;
403405 }
404406
405407 //
406- // The only property is the dictionary size, make sure it is valid
408+ // The only property is the dictionary size, make sure it is valid.
407409 //
408- size = blockHeader -> LzmaFlags .DictionarySize ;
409- if (size > 39 )
410- {
411- return false;
412- }
413-
410+ // We don't actually need to store or compare the size with anything since
411+ // the library expects the caller to always put in a buffer that's large
412+ // enough to contain the full uncompressed file (or calling it in "get size
413+ // only" mode to get this information).
414414 //
415- // And make sure it isn't larger than the output buffer
415+ // This output buffer can thus be smaller than the size of the dictionary
416+ // which is absolutely OK as long as that's actually the size of the output
417+ // file. If callers pass in a buffer size that's too small, decoding will
418+ // fail at later stages anyway, and that's incorrect use of minlzlib.
416419 //
417- size = ( 2 + ( size & 1 )) << (( size >> 1 ) + 11 ) ;
418- if (size > OutputSize )
420+ size = blockHeader -> LzmaFlags . u . s . DictionarySize ;
421+ if (size > 39 )
419422 {
420423 return false;
421424 }
422- #else
423- (void )(OutputSize );
424- #endif
425425#ifdef MINLZ_INTEGRITY_CHECKS
426426 //
427427 // Compute the header's CRC32 and make sure it's not corrupted
@@ -432,6 +432,7 @@ XzDecodeBlockHeader (
432432 {
433433 return false;
434434 }
435+ #endif
435436#endif
436437 return true;
437438}
@@ -451,17 +452,17 @@ XzDecode (
451452 DtInitialize (OutputBuffer , * OutputSize );
452453
453454 //
454- // Decode the stream header for validity
455+ // Decode the stream header for check for validity
455456 //
456457 if (!XzDecodeStreamHeader ())
457458 {
458459 return false;
459460 }
460461
461462 //
462- // Decode the block header to know the dictionary size
463+ // Decode the block header for check for validity
463464 //
464- if (!XzDecodeBlockHeader (* OutputSize ))
465+ if (!XzDecodeBlockHeader ())
465466 {
466467 return false;
467468 }
@@ -470,7 +471,7 @@ XzDecode (
470471 // Decode the actual block
471472 //
472473 if (!XzDecodeBlock (OutputBuffer , OutputSize ))
473- {
474+ {
474475 return false;
475476 }
476477#ifdef MINLZ_META_CHECKS
0 commit comments