From fa6a9c9654d243b2afb50883d1aa2cefa1ae4f92 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 14 Dec 2023 13:50:46 +0000 Subject: [PATCH] squashfs: fix off by one in directory counting (#193) 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++ {