libarchive.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. Index: libarchive/archive_read_support_compression_none.c
  2. --- libarchive/archive_read_support_compression_none.c.orig 2006-09-05 08:00:47 +0200
  3. +++ libarchive/archive_read_support_compression_none.c 2006-11-08 17:06:23 +0100
  4. @@ -257,7 +257,9 @@
  5. }
  6. /*
  7. - * Skip at most request bytes. Skipped data is marked as consumed.
  8. + * Skip forward by exactly the requested bytes or else return
  9. + * ARCHIVE_FATAL. Note that this differs from the contract for
  10. + * read_ahead, which does not gaurantee a minimum count.
  11. */
  12. static ssize_t
  13. archive_decompressor_none_skip(struct archive *a, size_t request)
  14. @@ -287,9 +289,7 @@
  15. if (request == 0)
  16. return (total_bytes_skipped);
  17. /*
  18. - * If no client_skipper is provided, just read the old way. It is very
  19. - * likely that after skipping, the request has not yet been fully
  20. - * satisfied (and is still > 0). In that case, read as well.
  21. + * If a client_skipper was provided, try that first.
  22. */
  23. if (a->client_skipper != NULL) {
  24. bytes_skipped = (a->client_skipper)(a, a->client_data,
  25. @@ -307,6 +307,12 @@
  26. a->raw_position += bytes_skipped;
  27. state->client_avail = state->client_total = 0;
  28. }
  29. + /*
  30. + * Note that client_skipper will usually not satisfy the
  31. + * full request (due to low-level blocking concerns),
  32. + * so even if client_skipper is provided, we may still
  33. + * have to use ordinary reads to finish out the request.
  34. + */
  35. while (request > 0) {
  36. const void* dummy_buffer;
  37. ssize_t bytes_read;
  38. @@ -314,6 +320,12 @@
  39. &dummy_buffer, request);
  40. if (bytes_read < 0)
  41. return (bytes_read);
  42. + if (bytes_read == 0) {
  43. + /* We hit EOF before we satisfied the skip request. */
  44. + archive_set_error(a, ARCHIVE_ERRNO_MISC,
  45. + "Truncated input file (need to skip %d bytes)", (int)request);
  46. + return (ARCHIVE_FATAL);
  47. + }
  48. assert(bytes_read >= 0); /* precondition for cast below */
  49. min = minimum((size_t)bytes_read, request);
  50. bytes_read = archive_decompressor_none_read_consume(a, min);