]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c
1. added functions header for BaseUefiDecompressLi
[mirror_edk2.git] / MdePkg / Library / BaseUefiDecompressLib / BaseUefiDecompressLib.c
1 /** @file
2 UEFI Decompress Library.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 Module Name: UefiDecompressLib.c
14
15 **/
16
17 //
18 // Decompression algorithm begins here
19 //
20 #define BITBUFSIZ 32
21 #define MAXMATCH 256
22 #define THRESHOLD 3
23 #define CODE_BIT 16
24 #define BAD_TABLE - 1
25
26 //
27 // C: Char&Len Set; P: Position Set; T: exTra Set
28 //
29 #define NC (0xff + MAXMATCH + 2 - THRESHOLD)
30 #define CBIT 9
31 #define MAXPBIT 5
32 #define TBIT 5
33 #define MAXNP ((1U << MAXPBIT) - 1)
34 #define NT (CODE_BIT + 3)
35 #if NT > MAXNP
36 #define NPT NT
37 #else
38 #define NPT MAXNP
39 #endif
40
41 typedef struct {
42 UINT8 *mSrcBase; ///< Starting address of compressed data
43 UINT8 *mDstBase; ///< Starting address of decompressed data
44 UINT32 mOutBuf;
45 UINT32 mInBuf;
46
47 UINT16 mBitCount;
48 UINT32 mBitBuf;
49 UINT32 mSubBitBuf;
50 UINT16 mBlockSize;
51 UINT32 mCompSize;
52 UINT32 mOrigSize;
53
54 UINT16 mBadTableFlag;
55
56 UINT16 mLeft[2 * NC - 1];
57 UINT16 mRight[2 * NC - 1];
58 UINT8 mCLen[NC];
59 UINT8 mPTLen[NPT];
60 UINT16 mCTable[4096];
61 UINT16 mPTTable[256];
62
63 ///
64 /// The length of the field 'Position Set Code Length Array Size' in Block Header.
65 /// For EFI 1.1 de/compression algorithm, mPBit = 4
66 /// For Tiano de/compression algorithm, mPBit = 5
67 ///
68 UINT8 mPBit;
69 } SCRATCH_DATA;
70
71 /**
72 Read NumOfBit of bits from source into mBitBuf
73
74 Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
75
76 @param Sd The global scratch data
77 @param NumOfBits The number of bits to shift and read.
78
79 **/
80 VOID
81 FillBuf (
82 IN SCRATCH_DATA *Sd,
83 IN UINT16 NumOfBits
84 )
85 {
86 //
87 // Left shift NumOfBits of bits in advance
88 //
89 Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);
90
91 //
92 // Copy data needed in bytes into mSbuBitBuf
93 //
94 while (NumOfBits > Sd->mBitCount) {
95
96 Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));
97
98 if (Sd->mCompSize > 0) {
99 //
100 // Get 1 byte into SubBitBuf
101 //
102 Sd->mCompSize--;
103 Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];
104 Sd->mBitCount = 8;
105
106 } else {
107 //
108 // No more bits from the source, just pad zero bit.
109 //
110 Sd->mSubBitBuf = 0;
111 Sd->mBitCount = 8;
112
113 }
114 }
115
116 //
117 // Caculate additional bit count read to update mBitCount
118 //
119 Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);
120
121 //
122 // Copy NumOfBits of bits from mSubBitBuf into mBitBuf
123 //
124 Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;
125 }
126
127 /**
128 Get NumOfBits of bits out from mBitBuf
129
130 Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
131 NumOfBits of bits from source. Returns NumOfBits of bits that are
132 popped out.
133
134 @param Sd The global scratch data.
135 @param NumOfBits The number of bits to pop and read.
136
137 @return The bits that are popped out.
138
139 **/
140 UINT32
141 GetBits (
142 IN SCRATCH_DATA *Sd,
143 IN UINT16 NumOfBits
144 )
145 {
146 UINT32 OutBits;
147
148 //
149 // Pop NumOfBits of Bits from Left
150 //
151 OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));
152
153 //
154 // Fill up mBitBuf from source
155 //
156 FillBuf (Sd, NumOfBits);
157
158 return OutBits;
159 }
160
161 /**
162 Creates Huffman Code mapping table according to code length array.
163
164 Creates Huffman Code mapping table for Extra Set, Char&Len Set
165 and Position Set according to code length array.
166
167 @param Sd The global scratch data
168 @param NumOfChar Number of symbols in the symbol set
169 @param BitLen Code length array
170 @param TableBits The width of the mapping table
171 @param Table The table
172
173 @retval 0 OK.
174 @retval BAD_TABLE The table is corrupted.
175
176 **/
177 UINT16
178 MakeTable (
179 IN SCRATCH_DATA *Sd,
180 IN UINT16 NumOfChar,
181 IN UINT8 *BitLen,
182 IN UINT16 TableBits,
183 OUT UINT16 *Table
184 )
185 {
186 UINT16 Count[17];
187 UINT16 Weight[17];
188 UINT16 Start[18];
189 UINT16 *Pointer;
190 UINT16 Index3;
191 volatile UINT16 Index;
192 UINT16 Len;
193 UINT16 Char;
194 UINT16 JuBits;
195 UINT16 Avail;
196 UINT16 NextCode;
197 UINT16 Mask;
198
199 for (Index = 1; Index <= 16; Index++) {
200 Count[Index] = 0;
201 }
202
203 for (Index = 0; Index < NumOfChar; Index++) {
204 Count[BitLen[Index]]++;
205 }
206
207 Start[1] = 0;
208
209 for (Index = 1; Index <= 16; Index++) {
210 Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));
211 }
212
213 if (Start[17] != 0) {
214 /*(1U << 16)*/
215 return (UINT16) BAD_TABLE;
216 }
217
218 JuBits = (UINT16) (16 - TableBits);
219
220 for (Index = 1; Index <= TableBits; Index++) {
221 Start[Index] >>= JuBits;
222 Weight[Index] = (UINT16) (1U << (TableBits - Index));
223 }
224
225 while (Index <= 16) {
226 Weight[Index] = (UINT16) (1U << (16 - Index));
227 Index++;
228 }
229
230 Index = (UINT16) (Start[TableBits + 1] >> JuBits);
231
232 if (Index != 0) {
233 Index3 = (UINT16) (1U << TableBits);
234 while (Index != Index3) {
235 Table[Index++] = 0;
236 }
237 }
238
239 Avail = NumOfChar;
240 Mask = (UINT16) (1U << (15 - TableBits));
241
242 for (Char = 0; Char < NumOfChar; Char++) {
243
244 Len = BitLen[Char];
245 if (Len == 0) {
246 continue;
247 }
248
249 NextCode = (UINT16) (Start[Len] + Weight[Len]);
250
251 if (Len <= TableBits) {
252
253 for (Index = Start[Len]; Index < NextCode; Index++) {
254 Table[Index] = Char;
255 }
256
257 } else {
258
259 Index3 = Start[Len];
260 Pointer = &Table[Index3 >> JuBits];
261 Index = (UINT16) (Len - TableBits);
262
263 while (Index != 0) {
264 if (*Pointer == 0) {
265 Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;
266 *Pointer = Avail++;
267 }
268
269 if (Index3 & Mask) {
270 Pointer = &Sd->mRight[*Pointer];
271 } else {
272 Pointer = &Sd->mLeft[*Pointer];
273 }
274
275 Index3 <<= 1;
276 Index--;
277 }
278
279 *Pointer = Char;
280
281 }
282
283 Start[Len] = NextCode;
284 }
285 //
286 // Succeeds
287 //
288 return 0;
289 }
290
291 /**
292 Decodes a position value.
293
294 Get a position value according to Position Huffman Table.
295
296 @param Sd the global scratch data
297
298 @return The position value decoded.
299
300 **/
301 UINT32
302 DecodeP (
303 IN SCRATCH_DATA *Sd
304 )
305 {
306 UINT16 Val;
307 UINT32 Mask;
308 UINT32 Pos;
309
310 Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
311
312 if (Val >= MAXNP) {
313 Mask = 1U << (BITBUFSIZ - 1 - 8);
314
315 do {
316
317 if (Sd->mBitBuf & Mask) {
318 Val = Sd->mRight[Val];
319 } else {
320 Val = Sd->mLeft[Val];
321 }
322
323 Mask >>= 1;
324 } while (Val >= MAXNP);
325 }
326 //
327 // Advance what we have read
328 //
329 FillBuf (Sd, Sd->mPTLen[Val]);
330
331 Pos = Val;
332 if (Val > 1) {
333 Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));
334 }
335
336 return Pos;
337 }
338
339 /**
340 Reads code lengths for the Extra Set or the Position Set.
341
342 Read in the Extra Set or Pointion Set Length Arrary, then
343 generate the Huffman code mapping for them.
344
345 @param Sd The global scratch data.
346 @param nn Number of symbols.
347 @param nbit Number of bits needed to represent nn.
348 @param Special The special symbol that needs to be taken care of.
349
350 @retval 0 OK.
351 @retval BAD_TABLE Table is corrupted.
352
353 **/
354 UINT16
355 ReadPTLen (
356 IN SCRATCH_DATA *Sd,
357 IN UINT16 nn,
358 IN UINT16 nbit,
359 IN UINT16 Special
360 )
361 {
362 UINT16 Number;
363 UINT16 CharC;
364 volatile UINT16 Index;
365 UINT32 Mask;
366
367 //
368 // Read Extra Set Code Length Array size
369 //
370 Number = (UINT16) GetBits (Sd, nbit);
371
372 if (Number == 0) {
373 //
374 // This represents only Huffman code used
375 //
376 CharC = (UINT16) GetBits (Sd, nbit);
377
378 for (Index = 0; Index < 256; Index++) {
379 Sd->mPTTable[Index] = CharC;
380 }
381
382 for (Index = 0; Index < nn; Index++) {
383 Sd->mPTLen[Index] = 0;
384 }
385
386 return 0;
387 }
388
389 Index = 0;
390
391 while (Index < Number) {
392
393 CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));
394
395 //
396 // If a code length is less than 7, then it is encoded as a 3-bit
397 // value. Or it is encoded as a series of "1"s followed by a
398 // terminating "0". The number of "1"s = Code length - 4.
399 //
400 if (CharC == 7) {
401 Mask = 1U << (BITBUFSIZ - 1 - 3);
402 while (Mask & Sd->mBitBuf) {
403 Mask >>= 1;
404 CharC += 1;
405 }
406 }
407
408 FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));
409
410 Sd->mPTLen[Index++] = (UINT8) CharC;
411
412 //
413 // For Code&Len Set,
414 // After the third length of the code length concatenation,
415 // a 2-bit value is used to indicated the number of consecutive
416 // zero lengths after the third length.
417 //
418 if (Index == Special) {
419 CharC = (UINT16) GetBits (Sd, 2);
420 while ((INT16) (--CharC) >= 0) {
421 Sd->mPTLen[Index++] = 0;
422 }
423 }
424 }
425
426 while (Index < nn) {
427 Sd->mPTLen[Index++] = 0;
428 }
429
430 return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);
431 }
432
433 /**
434 Reads code lengths for Char&Len Set.
435
436 Read in and decode the Char&Len Set Code Length Array, then
437 generate the Huffman Code mapping table for the Char&Len Set.
438
439 @param Sd the global scratch data
440
441 **/
442 VOID
443 ReadCLen (
444 SCRATCH_DATA *Sd
445 )
446 {
447 UINT16 Number;
448 UINT16 CharC;
449 volatile UINT16 Index;
450 UINT32 Mask;
451
452 Number = (UINT16) GetBits (Sd, CBIT);
453
454 if (Number == 0) {
455 //
456 // This represents only Huffman code used
457 //
458 CharC = (UINT16) GetBits (Sd, CBIT);
459
460 for (Index = 0; Index < NC; Index++) {
461 Sd->mCLen[Index] = 0;
462 }
463
464 for (Index = 0; Index < 4096; Index++) {
465 Sd->mCTable[Index] = CharC;
466 }
467
468 return ;
469 }
470
471 Index = 0;
472 while (Index < Number) {
473 CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
474 if (CharC >= NT) {
475 Mask = 1U << (BITBUFSIZ - 1 - 8);
476
477 do {
478
479 if (Mask & Sd->mBitBuf) {
480 CharC = Sd->mRight[CharC];
481 } else {
482 CharC = Sd->mLeft[CharC];
483 }
484
485 Mask >>= 1;
486
487 } while (CharC >= NT);
488 }
489 //
490 // Advance what we have read
491 //
492 FillBuf (Sd, Sd->mPTLen[CharC]);
493
494 if (CharC <= 2) {
495
496 if (CharC == 0) {
497 CharC = 1;
498 } else if (CharC == 1) {
499 CharC = (UINT16) (GetBits (Sd, 4) + 3);
500 } else if (CharC == 2) {
501 CharC = (UINT16) (GetBits (Sd, CBIT) + 20);
502 }
503
504 while ((INT16) (--CharC) >= 0) {
505 Sd->mCLen[Index++] = 0;
506 }
507
508 } else {
509
510 Sd->mCLen[Index++] = (UINT8) (CharC - 2);
511
512 }
513 }
514
515 while (Index < NC) {
516 Sd->mCLen[Index++] = 0;
517 }
518
519 MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);
520
521 return ;
522 }
523
524 /**
525 Decode a character/length value.
526
527 Read one value from mBitBuf, Get one code from mBitBuf. If it is at block boundary, generates
528 Huffman code mapping table for Extra Set, Code&Len Set and
529 Position Set.
530
531 @param Sd The global scratch data.
532
533 @return The value decoded.
534
535 **/
536 UINT16
537 DecodeC (
538 SCRATCH_DATA *Sd
539 )
540 {
541 UINT16 Index2;
542 UINT32 Mask;
543
544 if (Sd->mBlockSize == 0) {
545 //
546 // Starting a new block
547 // Read BlockSize from block header
548 //
549 Sd->mBlockSize = (UINT16) GetBits (Sd, 16);
550
551 //
552 // Read in the Extra Set Code Length Arrary,
553 // Generate the Huffman code mapping table for Extra Set.
554 //
555 Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);
556 if (Sd->mBadTableFlag != 0) {
557 return 0;
558 }
559
560 //
561 // Read in and decode the Char&Len Set Code Length Arrary,
562 // Generate the Huffman code mapping table for Char&Len Set.
563 //
564 ReadCLen (Sd);
565
566 //
567 // Read in the Position Set Code Length Arrary,
568 // Generate the Huffman code mapping table for the Position Set.
569 //
570 Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, Sd->mPBit, (UINT16) (-1));
571 if (Sd->mBadTableFlag != 0) {
572 return 0;
573 }
574 }
575
576 //
577 // Get one code according to Code&Set Huffman Table
578 //
579 Sd->mBlockSize--;
580 Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];
581
582 if (Index2 >= NC) {
583 Mask = 1U << (BITBUFSIZ - 1 - 12);
584
585 do {
586 if (Sd->mBitBuf & Mask) {
587 Index2 = Sd->mRight[Index2];
588 } else {
589 Index2 = Sd->mLeft[Index2];
590 }
591
592 Mask >>= 1;
593 } while (Index2 >= NC);
594 }
595 //
596 // Advance what we have read
597 //
598 FillBuf (Sd, Sd->mCLen[Index2]);
599
600 return Index2;
601 }
602
603 /**
604 Decode the source data and put the resulting data into the destination buffer.
605
606 Decode the source data and put the resulting data into the destination buffer.
607
608 @param Sd The global scratch data
609
610 **/
611 VOID
612 Decode (
613 SCRATCH_DATA *Sd
614 )
615 {
616 UINT16 BytesRemain;
617 UINT32 DataIdx;
618 UINT16 CharC;
619
620 BytesRemain = (UINT16) (-1);
621
622 DataIdx = 0;
623
624 for (;;) {
625 //
626 // Get one code from mBitBuf
627 //
628 CharC = DecodeC (Sd);
629 if (Sd->mBadTableFlag != 0) {
630 return ;
631 }
632
633 if (CharC < 256) {
634 //
635 // Process an Original character
636 //
637 if (Sd->mOutBuf >= Sd->mOrigSize) {
638 return ;
639 } else {
640 //
641 // Write orignal character into mDstBase
642 //
643 Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;
644 }
645
646 } else {
647 //
648 // Process a Pointer
649 //
650 CharC = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD));
651
652 //
653 // Get string length
654 //
655 BytesRemain = CharC;
656
657 //
658 // Locate string position
659 //
660 DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;
661
662 //
663 // Write BytesRemain of bytes into mDstBase
664 //
665 BytesRemain--;
666 while ((INT16) (BytesRemain) >= 0) {
667 Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];
668 if (Sd->mOutBuf >= Sd->mOrigSize) {
669 return ;
670 }
671
672 BytesRemain--;
673 }
674 }
675 }
676
677 return ;
678 }
679
680 /**
681 Retrieves the size of the uncompressed buffer and the size of the scratch buffer.
682
683 Retrieves the size of the uncompressed buffer and the temporary scratch buffer
684 required to decompress the buffer specified by Source and SourceSize.
685 If the size of the uncompressed buffer or the size of the scratch buffer cannot
686 be determined from the compressed data specified by Source and SourceData,
687 then RETURN_INVALID_PARAMETER is returned. Otherwise, the size of the uncompressed
688 buffer is returned in DestinationSize, the size of the scratch buffer is returned
689 in ScratchSize, and RETURN_SUCCESS is returned.
690 This function does not have scratch buffer available to perform a thorough
691 checking of the validity of the source data. It just retrieves the "Original Size"
692 field from the beginning bytes of the source data and output it as DestinationSize.
693 And ScratchSize is specific to the decompression implementation.
694
695 If Source is NULL, then ASSERT().
696 If DestinationSize is NULL, then ASSERT().
697 If ScratchSize is NULL, then ASSERT().
698
699 @param Source The source buffer containing the compressed data.
700 @param SourceSize The size, in bytes, of the source buffer.
701 @param DestinationSize A pointer to the size, in bytes, of the uncompressed buffer
702 that will be generated when the compressed buffer specified
703 by Source and SourceSize is decompressed..
704 @param ScratchSize A pointer to the size, in bytes, of the scratch buffer that
705 is required to decompress the compressed buffer specified
706 by Source and SourceSize.
707
708 @retval RETURN_SUCCESS The size of destination buffer and the size of scratch
709 buffer are successull retrieved.
710 @retval RETURN_INVALID_PARAMETER The source data is corrupted
711
712 **/
713 RETURN_STATUS
714 EFIAPI
715 UefiDecompressGetInfo (
716 IN CONST VOID *Source,
717 IN UINT32 SourceSize,
718 OUT UINT32 *DestinationSize,
719 OUT UINT32 *ScratchSize
720 )
721 {
722 UINT32 CompressedSize;
723
724 ASSERT (Source != NULL);
725 ASSERT (DestinationSize != NULL);
726 ASSERT (ScratchSize != NULL);
727
728 *ScratchSize = sizeof (SCRATCH_DATA);
729
730 if (SourceSize < 8) {
731 return RETURN_INVALID_PARAMETER;
732 }
733
734 CopyMem (&CompressedSize, Source, sizeof (UINT32));
735 CopyMem (DestinationSize, (VOID *)((UINT8 *)Source + 4), sizeof (UINT32));
736
737 if (SourceSize < (CompressedSize + 8)) {
738 return RETURN_INVALID_PARAMETER;
739 }
740
741 return RETURN_SUCCESS;
742 }
743
744 /**
745 Decompresses a compressed source buffer.
746
747 This function is designed so that the decompression algorithm can be implemented
748 without using any memory services. As a result, this function is not allowed to
749 call any memory allocation services in its implementation. It is the caller¡¯s r
750 esponsibility to allocate and free the Destination and Scratch buffers.
751 If the compressed source data specified by Source is sucessfully decompressed
752 into Destination, then RETURN_SUCCESS is returned. If the compressed source data
753 specified by Source is not in a valid compressed data format,
754 then RETURN_INVALID_PARAMETER is returned.
755
756 If Source is NULL, then ASSERT().
757 If Destination is NULL, then ASSERT().
758 If the required scratch buffer size > 0 and Scratch is NULL, then ASSERT().
759
760 @param Source The source buffer containing the compressed data.
761 @param Destination The destination buffer to store the decompressed data
762 @param Scratch A temporary scratch buffer that is used to perform the decompression.
763 This is an optional parameter that may be NULL if the
764 required scratch buffer size is 0.
765
766 @retval RETURN_SUCCESS Decompression is successfull
767 @retval RETURN_INVALID_PARAMETER The source data is corrupted
768
769 **/
770 RETURN_STATUS
771 EFIAPI
772 UefiDecompress (
773 IN CONST VOID *Source,
774 IN OUT VOID *Destination,
775 IN OUT VOID *Scratch
776 )
777 {
778 volatile UINT32 Index;
779 UINT32 CompSize;
780 UINT32 OrigSize;
781 SCRATCH_DATA *Sd;
782 CONST UINT8 *Src;
783 UINT8 *Dst;
784
785 ASSERT (Source != NULL);
786 ASSERT (Destination != NULL);
787 ASSERT (Scratch != NULL);
788
789 Src = Source;
790 Dst = Destination;
791
792 Sd = (SCRATCH_DATA *) Scratch;
793
794 CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);
795 OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
796
797 //
798 // If compressed file size is 0, return
799 //
800 if (OrigSize == 0) {
801 return RETURN_SUCCESS;
802 }
803
804 Src = Src + 8;
805
806 for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) {
807 ((UINT8 *) Sd)[Index] = 0;
808 }
809 //
810 // The length of the field 'Position Set Code Length Array Size' in Block Header.
811 // For EFI 1.1 de/compression algorithm(Version 1), mPBit = 4
812 // For Tiano de/compression algorithm(Version 2), mPBit = 5
813 //
814 Sd->mPBit = 4;
815 Sd->mSrcBase = (UINT8 *)Src;
816 Sd->mDstBase = Dst;
817 //
818 // CompSize and OrigSize are caculated in bytes
819 //
820 Sd->mCompSize = CompSize;
821 Sd->mOrigSize = OrigSize;
822
823 //
824 // Fill the first BITBUFSIZ bits
825 //
826 FillBuf (Sd, BITBUFSIZ);
827
828 //
829 // Decompress it
830 //
831 Decode (Sd);
832
833 if (Sd->mBadTableFlag != 0) {
834 //
835 // Something wrong with the source
836 //
837 return RETURN_INVALID_PARAMETER;
838 }
839
840 return RETURN_SUCCESS;
841 }