Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.8 KiB

  1. /* DEC/CMS REPLACEMENT HISTORY, Element UNZIP.C */
  2. /* *1 14-NOV-1996 10:26:58 ANIGBOGU "[113914]Decompress data in zip format using the inflate algorithm" */
  3. /* DEC/CMS REPLACEMENT HISTORY, Element UNZIP.C */
  4. /* DEC/CMS REPLACEMENT HISTORY, Element UNZIP.C */
  5. /* PRIVATE FILE
  6. ******************************************************************************
  7. **
  8. ** (c) Copyright Schlumberger Technology Corp., unpublished work, created 1996.
  9. **
  10. ** This computer program includes Confidential, Proprietary Information and is
  11. ** a Trade Secret of Schlumberger Technology Corp. All use, disclosure, and/or
  12. ** reproduction is prohibited unless authorized in writing by Schlumberger.
  13. ** All Rights Reserved.
  14. **
  15. ******************************************************************************
  16. **
  17. ** compress/unzip.c
  18. **
  19. ** PURPOSE
  20. **
  21. ** Decompress data using the inflate algorithm.
  22. **
  23. ** The code in this file is derived from the file funzip.c written
  24. ** and put in the public domain by Mark Adler.
  25. **
  26. **
  27. ** SPECIAL REQUIREMENTS & NOTES
  28. **
  29. ** AUTHOR
  30. **
  31. ** J. C. Anigbogu
  32. ** Austin Systems Center
  33. ** Nov 1996
  34. **
  35. ******************************************************************************
  36. */
  37. #include "comppriv.h"
  38. #define EXTHDR 16 /* size of extended local header, inc sig */
  39. /* ===========================================================================
  40. *
  41. * IN assertions: the buffer Input contains already the beginning of
  42. * the compressed data, from offsets inptr to InputSize-1 included.
  43. * The magic header has already been checked. The output buffer is cleared.
  44. */
  45. CompressStatus_t
  46. Unzip(
  47. int Method,
  48. CompParam_t *Comp
  49. )
  50. {
  51. unsigned long OriginalCRC = 0; /* original crc */
  52. unsigned long OriginalLength = 0; /* original uncompressed length */
  53. unsigned long Count; /* counter */
  54. int Pos;
  55. unsigned char LocalBuffer[EXTHDR]; /* extended local header */
  56. unsigned char *Buffer, *Ptr;
  57. CompressStatus_t Status;
  58. Comp->pCRC->Compute(NULL, 0); /* initialize crc */
  59. /* Decompress */
  60. if (Method == STORED)
  61. {
  62. /* Get the crc and original length */
  63. /* crc32 (see algorithm.doc)
  64. * uncompressed input size modulo 2^32
  65. */
  66. LocalBuffer[0] = 0; /* To get around lint error 771 */
  67. for (Pos = 0; Pos < 8; Pos++)
  68. {
  69. LocalBuffer[Pos] = (unsigned char)GetByte(Comp); /* may cause an error if EOF */
  70. }
  71. OriginalCRC = LG(LocalBuffer);
  72. OriginalLength = LG(LocalBuffer+4);
  73. Ptr = Buffer = (unsigned char *)CompressMalloc((unsigned int)OriginalLength, &Status);
  74. if (Status != COMPRESS_OK)
  75. return Status;
  76. for (Count = 0; Count < OriginalLength; Count++)
  77. *(Ptr++) = (unsigned char)GetByte(Comp);
  78. WriteBuffer(Comp, Buffer, (unsigned int)OriginalLength);
  79. Comp->BytesOut = OriginalLength;
  80. CompressFree((char *)Buffer);
  81. return COMPRESS_OK;
  82. }
  83. if ((Status = Inflate(Comp)) != COMPRESS_OK)
  84. return Status;
  85. /* Get the crc and original length */
  86. /* crc32 (see algorithm.doc)
  87. * uncompressed input size modulo 2^32
  88. */
  89. LocalBuffer[0] = 0; /* To skirt around lint error 771 */
  90. for (Pos = 0; Pos < 8; Pos++)
  91. {
  92. LocalBuffer[Pos] = (unsigned char)GetByte(Comp); /* may cause an error if EOF */
  93. }
  94. OriginalCRC = LG(LocalBuffer);
  95. OriginalLength = LG(LocalBuffer+4);
  96. /* Validate decompression */
  97. if (OriginalCRC != (unsigned __int32)(*Comp->pCRC))
  98. return CRC_ERROR;
  99. if (OriginalLength != (unsigned long)Comp->BytesOut)
  100. return LENGTH_ERROR;
  101. return COMPRESS_OK;
  102. }