From 7a484b511ff7a5e3fdd42715ac8cd32ff2c732a8 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 12 Dec 2023 15:33:18 +0000 Subject: [PATCH] squashfs: fix off by one in directory counting This was causing "corrupted directory, had 257 entries instead of max 256" errors, however this was because parseDirectoryHeader had already added one to the count. --- filesystem/squashfs/directory.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filesystem/squashfs/directory.go b/filesystem/squashfs/directory.go index 0f5bd8d5..804d3392 100644 --- a/filesystem/squashfs/directory.go +++ b/filesystem/squashfs/directory.go @@ -64,8 +64,8 @@ func parseDirectory(b []byte) (*directory, error) { if err != nil { return nil, fmt.Errorf("could not parse directory header: %v", err) } - if directoryHeader.count+1 > maxDirEntries { - return nil, fmt.Errorf("corrupted directory, had %d entries instead of max %d", directoryHeader.count+1, maxDirEntries) + if directoryHeader.count > maxDirEntries { + return nil, fmt.Errorf("corrupted directory, had %d entries instead of max %d", directoryHeader.count, maxDirEntries) } pos += dirHeaderSize for count := uint32(0); count < directoryHeader.count; count++ {