View | Details | Raw Unified | Return to bug 82635
Collapse All | Expand All

(-)bzip2-1.0.2/bzip2.c (-2 / +6 lines)
Lines 525-530 Bool uncompressStream ( FILE *zStream, F Link Here
525
   UChar   obuf[5000];
525
   UChar   obuf[5000];
526
   UChar   unused[BZ_MAX_UNUSED];
526
   UChar   unused[BZ_MAX_UNUSED];
527
   Int32   nUnused;
527
   Int32   nUnused;
528
   void*   unusedTmpV;
528
   UChar*  unusedTmp;
529
   UChar*  unusedTmp;
529
530
530
   nUnused = 0;
531
   nUnused = 0;
Lines 554-562 Bool uncompressStream ( FILE *zStream, F Link Here
554
      }
555
      }
555
      if (bzerr != BZ_STREAM_END) goto errhandler;
556
      if (bzerr != BZ_STREAM_END) goto errhandler;
556
557
557
      BZ2_bzReadGetUnused ( &bzerr, bzf, (void**)(&unusedTmp), &nUnused );
558
      BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
558
      if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
559
      if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
559
560
561
      unusedTmp = (UChar*)unusedTmpV;
560
      for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
562
      for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
561
563
562
      BZ2_bzReadClose ( &bzerr, bzf );
564
      BZ2_bzReadClose ( &bzerr, bzf );
Lines 639-644 Bool testStream ( FILE *zStream ) Link Here
639
   UChar   obuf[5000];
641
   UChar   obuf[5000];
640
   UChar   unused[BZ_MAX_UNUSED];
642
   UChar   unused[BZ_MAX_UNUSED];
641
   Int32   nUnused;
643
   Int32   nUnused;
644
   void*   unusedTmpV;
642
   UChar*  unusedTmp;
645
   UChar*  unusedTmp;
643
646
644
   nUnused = 0;
647
   nUnused = 0;
Lines 662-670 Bool testStream ( FILE *zStream ) Link Here
662
      }
665
      }
663
      if (bzerr != BZ_STREAM_END) goto errhandler;
666
      if (bzerr != BZ_STREAM_END) goto errhandler;
664
667
665
      BZ2_bzReadGetUnused ( &bzerr, bzf, (void**)(&unusedTmp), &nUnused );
668
      BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
666
      if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
669
      if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
667
670
671
      unusedTmp = (UChar*)unusedTmpV;
668
      for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
672
      for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
669
673
670
      BZ2_bzReadClose ( &bzerr, bzf );
674
      BZ2_bzReadClose ( &bzerr, bzf );
(-)bzip2-1.0.2/bzlib.c (-14 / +37 lines)
Lines 574-581 int BZ_API(BZ2_bzDecompressInit) Link Here
574
574
575
575
576
/*---------------------------------------------------*/
576
/*---------------------------------------------------*/
577
/* Return  True iff data corruption is discovered.
578
   Returns False if there is no problem.
579
*/
577
static
580
static
578
void unRLE_obuf_to_output_FAST ( DState* s )
581
Bool unRLE_obuf_to_output_FAST ( DState* s )
579
{
582
{
580
   UChar k1;
583
   UChar k1;
581
584
Lines 584-590 void unRLE_obuf_to_output_FAST ( DState* Link Here
584
      while (True) {
587
      while (True) {
585
         /* try to finish existing run */
588
         /* try to finish existing run */
586
         while (True) {
589
         while (True) {
587
            if (s->strm->avail_out == 0) return;
590
            if (s->strm->avail_out == 0) return False;
588
            if (s->state_out_len == 0) break;
591
            if (s->state_out_len == 0) break;
589
            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
592
            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
590
            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
593
            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
Lines 594-603 void unRLE_obuf_to_output_FAST ( DState* Link Here
594
            s->strm->total_out_lo32++;
597
            s->strm->total_out_lo32++;
595
            if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
598
            if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++;
596
         }
599
         }
597
   
600
598
         /* can a new run be started? */
601
         /* can a new run be started? */
599
         if (s->nblock_used == s->save_nblock+1) return;
602
         if (s->nblock_used == s->save_nblock+1) return False;
600
               
603
               
604
         /* Only caused by corrupt data stream? */
605
         if (s->nblock_used > s->save_nblock+1)
606
            return True;
601
   
607
   
602
         s->state_out_len = 1;
608
         s->state_out_len = 1;
603
         s->state_out_ch = s->k0;
609
         s->state_out_ch = s->k0;
Lines 667-672 void unRLE_obuf_to_output_FAST ( DState* Link Here
667
               cs_avail_out--;
673
               cs_avail_out--;
668
            }
674
            }
669
         }   
675
         }   
676
         /* Only caused by corrupt data stream? */
677
         if (c_nblock_used > s_save_nblockPP)
678
            return True;
679
670
         /* can a new run be started? */
680
         /* can a new run be started? */
671
         if (c_nblock_used == s_save_nblockPP) {
681
         if (c_nblock_used == s_save_nblockPP) {
672
            c_state_out_len = 0; goto return_notr;
682
            c_state_out_len = 0; goto return_notr;
Lines 712-717 void unRLE_obuf_to_output_FAST ( DState* Link Here
712
      s->strm->avail_out    = cs_avail_out;
722
      s->strm->avail_out    = cs_avail_out;
713
      /* end save */
723
      /* end save */
714
   }
724
   }
725
   return False;
715
}
726
}
716
727
717
728
Lines 732-739 __inline__ Int32 BZ2_indexIntoF ( Int32 Link Here
732
743
733
744
734
/*---------------------------------------------------*/
745
/*---------------------------------------------------*/
746
/* Return  True iff data corruption is discovered.
747
   Returns False if there is no problem.
748
*/
735
static
749
static
736
void unRLE_obuf_to_output_SMALL ( DState* s )
750
Bool unRLE_obuf_to_output_SMALL ( DState* s )
737
{
751
{
738
   UChar k1;
752
   UChar k1;
739
753
Lines 742-748 void unRLE_obuf_to_output_SMALL ( DState Link Here
742
      while (True) {
756
      while (True) {
743
         /* try to finish existing run */
757
         /* try to finish existing run */
744
         while (True) {
758
         while (True) {
745
            if (s->strm->avail_out == 0) return;
759
            if (s->strm->avail_out == 0) return False;
746
            if (s->state_out_len == 0) break;
760
            if (s->state_out_len == 0) break;
747
            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
761
            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
748
            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
762
            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
Lines 754-761 void unRLE_obuf_to_output_SMALL ( DState Link Here
754
         }
768
         }
755
   
769
   
756
         /* can a new run be started? */
770
         /* can a new run be started? */
757
         if (s->nblock_used == s->save_nblock+1) return;
771
         if (s->nblock_used == s->save_nblock+1) return False;
758
               
772
773
         /* Only caused by corrupt data stream? */
774
         if (s->nblock_used > s->save_nblock+1)
775
            return True;
759
   
776
   
760
         s->state_out_len = 1;
777
         s->state_out_len = 1;
761
         s->state_out_ch = s->k0;
778
         s->state_out_ch = s->k0;
Lines 788-794 void unRLE_obuf_to_output_SMALL ( DState Link Here
788
      while (True) {
805
      while (True) {
789
         /* try to finish existing run */
806
         /* try to finish existing run */
790
         while (True) {
807
         while (True) {
791
            if (s->strm->avail_out == 0) return;
808
            if (s->strm->avail_out == 0) return False;
792
            if (s->state_out_len == 0) break;
809
            if (s->state_out_len == 0) break;
793
            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
810
            *( (UChar*)(s->strm->next_out) ) = s->state_out_ch;
794
            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
811
            BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch );
Lines 800-806 void unRLE_obuf_to_output_SMALL ( DState Link Here
800
         }
817
         }
801
   
818
   
802
         /* can a new run be started? */
819
         /* can a new run be started? */
803
         if (s->nblock_used == s->save_nblock+1) return;
820
         if (s->nblock_used == s->save_nblock+1) return False;
821
822
         /* Only caused by corrupt data stream? */
823
         if (s->nblock_used > s->save_nblock+1)
824
            return True;
804
   
825
   
805
         s->state_out_len = 1;
826
         s->state_out_len = 1;
806
         s->state_out_ch = s->k0;
827
         s->state_out_ch = s->k0;
Lines 830-835 void unRLE_obuf_to_output_SMALL ( DState Link Here
830
/*---------------------------------------------------*/
851
/*---------------------------------------------------*/
831
int BZ_API(BZ2_bzDecompress) ( bz_stream *strm )
852
int BZ_API(BZ2_bzDecompress) ( bz_stream *strm )
832
{
853
{
854
   Bool    corrupt;
833
   DState* s;
855
   DState* s;
834
   if (strm == NULL) return BZ_PARAM_ERROR;
856
   if (strm == NULL) return BZ_PARAM_ERROR;
835
   s = strm->state;
857
   s = strm->state;
Lines 840-851 int BZ_API(BZ2_bzDecompress) ( bz_stream Link Here
840
      if (s->state == BZ_X_IDLE) return BZ_SEQUENCE_ERROR;
862
      if (s->state == BZ_X_IDLE) return BZ_SEQUENCE_ERROR;
841
      if (s->state == BZ_X_OUTPUT) {
863
      if (s->state == BZ_X_OUTPUT) {
842
         if (s->smallDecompress)
864
         if (s->smallDecompress)
843
            unRLE_obuf_to_output_SMALL ( s ); else
865
            corrupt = unRLE_obuf_to_output_SMALL ( s ); else
844
            unRLE_obuf_to_output_FAST  ( s );
866
            corrupt = unRLE_obuf_to_output_FAST  ( s );
867
         if (corrupt) return BZ_DATA_ERROR;
845
         if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) {
868
         if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) {
846
            BZ_FINALISE_CRC ( s->calculatedBlockCRC );
869
            BZ_FINALISE_CRC ( s->calculatedBlockCRC );
847
            if (s->verbosity >= 3) 
870
            if (s->verbosity >= 3) 
848
               VPrintf2 ( " {0x%x, 0x%x}", s->storedBlockCRC, 
871
               VPrintf2 ( " {0x%08x, 0x%08x}", s->storedBlockCRC, 
849
                          s->calculatedBlockCRC );
872
                          s->calculatedBlockCRC );
850
            if (s->verbosity >= 2) VPrintf0 ( "]" );
873
            if (s->verbosity >= 2) VPrintf0 ( "]" );
851
            if (s->calculatedBlockCRC != s->storedBlockCRC)
874
            if (s->calculatedBlockCRC != s->storedBlockCRC)
Lines 863-869 int BZ_API(BZ2_bzDecompress) ( bz_stream Link Here
863
         Int32 r = BZ2_decompress ( s );
886
         Int32 r = BZ2_decompress ( s );
864
         if (r == BZ_STREAM_END) {
887
         if (r == BZ_STREAM_END) {
865
            if (s->verbosity >= 3)
888
            if (s->verbosity >= 3)
866
               VPrintf2 ( "\n    combined CRCs: stored = 0x%x, computed = 0x%x", 
889
               VPrintf2 ( "\n    combined CRCs: stored = 0x%08x, computed = 0x%08x", 
867
                          s->storedCombinedCRC, s->calculatedCombinedCRC );
890
                          s->storedCombinedCRC, s->calculatedCombinedCRC );
868
            if (s->calculatedCombinedCRC != s->storedCombinedCRC)
891
            if (s->calculatedCombinedCRC != s->storedCombinedCRC)
869
               return BZ_DATA_ERROR;
892
               return BZ_DATA_ERROR;
(-)bzip2-1.0.2/compress.c (-5 / +7 lines)
Lines 488-496 void sendMTFValues ( EState* s ) Link Here
488
      /*--
488
      /*--
489
        Recompute the tables based on the accumulated frequencies.
489
        Recompute the tables based on the accumulated frequencies.
490
      --*/
490
      --*/
491
      /* maxLen was changed from 20 to 17 in bzip2-1.0.3.  See 
492
         comment in huffman.c for details. */
491
      for (t = 0; t < nGroups; t++)
493
      for (t = 0; t < nGroups; t++)
492
         BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]), 
494
         BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]), 
493
                                 alphaSize, 20 );
495
                                 alphaSize, 17 /*20*/ );
494
   }
496
   }
495
497
496
498
Lines 527-533 void sendMTFValues ( EState* s ) Link Here
527
         if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
529
         if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
528
         if (s->len[t][i] < minLen) minLen = s->len[t][i];
530
         if (s->len[t][i] < minLen) minLen = s->len[t][i];
529
      }
531
      }
530
      AssertH ( !(maxLen > 20), 3004 );
532
      AssertH ( !(maxLen > 17 /*20*/ ), 3004 );
531
      AssertH ( !(minLen < 1),  3005 );
533
      AssertH ( !(minLen < 1),  3005 );
532
      BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]), 
534
      BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]), 
533
                          minLen, maxLen, alphaSize );
535
                          minLen, maxLen, alphaSize );
Lines 651-658 void BZ2_compressBlock ( EState* s, Bool Link Here
651
      if (s->blockNo > 1) s->numZ = 0;
653
      if (s->blockNo > 1) s->numZ = 0;
652
654
653
      if (s->verbosity >= 2)
655
      if (s->verbosity >= 2)
654
         VPrintf4( "    block %d: crc = 0x%8x, "
656
         VPrintf4( "    block %d: crc = 0x%08x, "
655
                   "combined CRC = 0x%8x, size = %d\n",
657
                   "combined CRC = 0x%08x, size = %d\n",
656
                   s->blockNo, s->blockCRC, s->combinedCRC, s->nblock );
658
                   s->blockNo, s->blockCRC, s->combinedCRC, s->nblock );
657
659
658
      BZ2_blockSort ( s );
660
      BZ2_blockSort ( s );
Lines 703-709 void BZ2_compressBlock ( EState* s, Bool Link Here
703
      bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 );
705
      bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 );
704
      bsPutUInt32 ( s, s->combinedCRC );
706
      bsPutUInt32 ( s, s->combinedCRC );
705
      if (s->verbosity >= 2)
707
      if (s->verbosity >= 2)
706
         VPrintf1( "    final combined CRC = 0x%x\n   ", s->combinedCRC );
708
         VPrintf1( "    final combined CRC = 0x%08x\n   ", s->combinedCRC );
707
      bsFinishWrite ( s );
709
      bsFinishWrite ( s );
708
   }
710
   }
709
}
711
}
(-)bzip2-1.0.2/decompress.c (-5 / +11 lines)
Lines 524-540 Int32 BZ2_decompress ( DState* s ) Link Here
524
      if (s->origPtr < 0 || s->origPtr >= nblock)
524
      if (s->origPtr < 0 || s->origPtr >= nblock)
525
         RETURN(BZ_DATA_ERROR);
525
         RETURN(BZ_DATA_ERROR);
526
526
527
      /*-- Set up cftab to facilitate generation of T^(-1) --*/
528
      s->cftab[0] = 0;
529
      for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
530
      for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
531
      for (i = 0; i <= 256; i++) {
532
         if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
533
            /* s->cftab[i] can legitimately be == nblock */
534
            RETURN(BZ_DATA_ERROR);
535
         }
536
      }
537
527
      s->state_out_len = 0;
538
      s->state_out_len = 0;
528
      s->state_out_ch  = 0;
539
      s->state_out_ch  = 0;
529
      BZ_INITIALISE_CRC ( s->calculatedBlockCRC );
540
      BZ_INITIALISE_CRC ( s->calculatedBlockCRC );
530
      s->state = BZ_X_OUTPUT;
541
      s->state = BZ_X_OUTPUT;
531
      if (s->verbosity >= 2) VPrintf0 ( "rt+rld" );
542
      if (s->verbosity >= 2) VPrintf0 ( "rt+rld" );
532
543
533
      /*-- Set up cftab to facilitate generation of T^(-1) --*/
534
      s->cftab[0] = 0;
535
      for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
536
      for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
537
538
      if (s->smallDecompress) {
544
      if (s->smallDecompress) {
539
545
540
         /*-- Make a copy of cftab, used in generation of T --*/
546
         /*-- Make a copy of cftab, used in generation of T --*/
(-)bzip2-1.0.2/huffman.c (-1 / +18 lines)
Lines 162-168 void BZ2_hbMakeCodeLengths ( UChar *len, Link Here
162
      
162
      
163
      if (! tooLong) break;
163
      if (! tooLong) break;
164
164
165
      for (i = 1; i < alphaSize; i++) {
165
      /* 17 Oct 04: keep-going condition for the following loop used
166
         to be 'i < alphaSize', which missed the last element,
167
         theoretically leading to the possibility of the compressor
168
         looping.  However, this count-scaling step is only needed if
169
         one of the generated Huffman code words is longer than
170
         maxLen, which up to and including version 1.0.2 was 20 bits,
171
         which is extremely unlikely.  In version 1.0.3 maxLen was
172
         changed to 17 bits, which has minimal effect on compression
173
         ratio, but does mean this scaling step is used from time to
174
         time, enough to verify that it works.
175
176
         This means that bzip2-1.0.3 and later will only produce
177
         Huffman codes with a maximum length of 17 bits.  However, in
178
         order to preserve backwards compatibility with bitstreams
179
         produced by versions pre-1.0.3, the decompressor must still
180
         handle lengths of up to 20. */
181
182
      for (i = 1; i <= alphaSize; i++) {
166
         j = weight[i] >> 8;
183
         j = weight[i] >> 8;
167
         j = 1 + (j / 2);
184
         j = 1 + (j / 2);
168
         weight[i] = j << 8;
185
         weight[i] = j << 8;

Return to bug 82635