]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
read_disk: Check if off_t can overflow size_t 3146/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 14 Jun 2026 09:14:03 +0000 (11:14 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 14 Jun 2026 09:14:03 +0000 (11:14 +0200)
Make sure that the content of the link can fit into a size_t. This
should be always true, but be cautious with 32 bit systems and very
weird filesystems (possibly through fuse).

I took SSIZE_MAX as upper limit due to signedness and eventual readlink
calls which would fail with larger values anyway.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_read_disk_entry_from_file.c

index b5f1dd96327e9b492cc5130df5f678de95c1075a..c4ad595fa4d893aa59e0f077b454ea35776ce3a9 100644 (file)
@@ -256,6 +256,11 @@ archive_read_disk_entry_from_file(struct archive *_a,
                char *linkbuffer;
                ssize_t lnklen;
 
+               if (st->st_size >= SSIZE_MAX) {
+                       archive_set_error(&a->archive, ENOMEM,
+                           "Couldn't read link data");
+                       return (ARCHIVE_FAILED);
+               }
                linkbuffer = malloc(linkbuffer_len + 1);
                if (linkbuffer == NULL) {
                        archive_set_error(&a->archive, ENOMEM,