|
| 1 | +From 73e4f2971e74282d723e8963a30d0a4b35509e39 Mon Sep 17 00:00:00 2001 |
| 2 | +From: kavyasree <kkaitepalli@microsoft.com> |
| 3 | +Date: Mon, 7 Apr 2025 11:46:42 +0530 |
| 4 | +Subject: [PATCH] Error handling in __archive_read_ahead |
| 5 | +Reference: https://github.com/libarchive/libarchive/commit/565b5aea491671ae33df1ca63697c10d54c00165 |
| 6 | +--- |
| 7 | + .../archive_read_support_format_tar.c | 17 +++++++---------- |
| 8 | + 1 file changed, 7 insertions(+), 10 deletions(-) |
| 9 | + |
| 10 | +diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c |
| 11 | +index c63d46fc..3e0af9f8 100644 |
| 12 | +--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c |
| 13 | ++++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c |
| 14 | +@@ -621,8 +621,6 @@ archive_read_format_tar_read_data(struct archive_read *a, |
| 15 | + } |
| 16 | + |
| 17 | + *buff = __archive_read_ahead(a, 1, &bytes_read); |
| 18 | +- if (bytes_read < 0) |
| 19 | +- return (ARCHIVE_FATAL); |
| 20 | + if (*buff == NULL) { |
| 21 | + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, |
| 22 | + "Truncated tar archive"); |
| 23 | +@@ -707,13 +705,11 @@ tar_read_header(struct archive_read *a, struct tar *tar, |
| 24 | + |
| 25 | + /* Read 512-byte header record */ |
| 26 | + h = __archive_read_ahead(a, 512, &bytes); |
| 27 | +- if (bytes < 0) |
| 28 | +- return ((int)bytes); |
| 29 | + if (bytes == 0) { /* EOF at a block boundary. */ |
| 30 | + /* Some writers do omit the block of nulls. <sigh> */ |
| 31 | + return (ARCHIVE_EOF); |
| 32 | + } |
| 33 | +- if (bytes < 512) { /* Short block at EOF; this is bad. */ |
| 34 | ++ if (h == NULL) { /* Short block at EOF; this is bad. */ |
| 35 | + archive_set_error(&a->archive, |
| 36 | + ARCHIVE_ERRNO_FILE_FORMAT, |
| 37 | + "Truncated tar archive"); |
| 38 | +@@ -1449,6 +1445,9 @@ read_mac_metadata_blob(struct archive_read *a, struct tar *tar, |
| 39 | + */ |
| 40 | + data = __archive_read_ahead(a, (size_t)size, NULL); |
| 41 | + if (data == NULL) { |
| 42 | ++ archive_set_error(&a->archive, EINVAL, |
| 43 | ++ "Truncated archive" |
| 44 | ++ " detected while reading macOS metadata"); |
| 45 | + *unconsumed = 0; |
| 46 | + return (ARCHIVE_FATAL); |
| 47 | + } |
| 48 | +@@ -2317,9 +2316,7 @@ gnu_sparse_old_read(struct archive_read *a, struct tar *tar, |
| 49 | + do { |
| 50 | + tar_flush_unconsumed(a, unconsumed); |
| 51 | + data = __archive_read_ahead(a, 512, &bytes_read); |
| 52 | +- if (bytes_read < 0) |
| 53 | +- return (ARCHIVE_FATAL); |
| 54 | +- if (bytes_read < 512) { |
| 55 | ++ if (data == NULL) { |
| 56 | + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, |
| 57 | + "Truncated tar archive " |
| 58 | + "detected while reading sparse file data"); |
| 59 | +@@ -2727,7 +2724,7 @@ readline(struct archive_read *a, struct tar *tar, const char **start, |
| 60 | + tar_flush_unconsumed(a, unconsumed); |
| 61 | + |
| 62 | + t = __archive_read_ahead(a, 1, &bytes_read); |
| 63 | +- if (bytes_read <= 0) |
| 64 | ++ if (bytes_read <= 0 || t == NULL) |
| 65 | + return (ARCHIVE_FATAL); |
| 66 | + s = t; /* Start of line? */ |
| 67 | + p = memchr(t, '\n', bytes_read); |
| 68 | +@@ -2768,7 +2765,7 @@ readline(struct archive_read *a, struct tar *tar, const char **start, |
| 69 | + } |
| 70 | + /* Read some more. */ |
| 71 | + t = __archive_read_ahead(a, 1, &bytes_read); |
| 72 | +- if (bytes_read <= 0) |
| 73 | ++ if (bytes_read <= 0 || t == NULL) |
| 74 | + return (ARCHIVE_FATAL); |
| 75 | + s = t; /* Start of line? */ |
| 76 | + p = memchr(t, '\n', bytes_read); |
| 77 | +-- |
| 78 | +2.34.1 |
| 79 | + |
0 commit comments