3
0

check_header_gzip.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  4. */
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include "libbb.h"
  8. #include "unarchive.h" /* for external decl of check_header_gzip */
  9. void check_header_gzip(int src_fd)
  10. {
  11. union {
  12. unsigned char raw[8];
  13. struct {
  14. unsigned char method;
  15. unsigned char flags;
  16. unsigned int mtime;
  17. unsigned char xtra_flags;
  18. unsigned char os_flags;
  19. } formatted;
  20. } header;
  21. xread(src_fd, header.raw, 8);
  22. /* Check the compression method */
  23. if (header.formatted.method != 8) {
  24. bb_error_msg_and_die("unknown compression method %d",
  25. header.formatted.method);
  26. }
  27. if (header.formatted.flags & 0x04) {
  28. /* bit 2 set: extra field present */
  29. unsigned char extra_short;
  30. extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
  31. while (extra_short > 0) {
  32. /* Ignore extra field */
  33. xread_char(src_fd);
  34. extra_short--;
  35. }
  36. }
  37. /* Discard original name if any */
  38. if (header.formatted.flags & 0x08) {
  39. /* bit 3 set: original file name present */
  40. while(xread_char(src_fd) != 0);
  41. }
  42. /* Discard file comment if any */
  43. if (header.formatted.flags & 0x10) {
  44. /* bit 4 set: file comment present */
  45. while(xread_char(src_fd) != 0);
  46. }
  47. /* Read the header checksum */
  48. if (header.formatted.flags & 0x02) {
  49. xread_char(src_fd);
  50. xread_char(src_fd);
  51. }
  52. return;
  53. }