From 248494992442fbde7eb6ca3979a778d82fa86016 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 21 Jul 2021 09:41:47 +0200 Subject: Fix libsquashfs directory writer size accounting The squashfs readdir() implementation in the Linux kernel returns non-existing "." and ".." entries for offsets 0 and 1, and after that reads from disk. For convenience, it was decided to store an off-by-3 value on disk instead of doing complex primary school math to adjust for this. This didn't show up until now, because the kernel implementation trusts the value from the directory header more than the actual size in the inode and happily reads 3 more than the inode would allow it to. This only showed up with 7-zip which subtracts 3 from the size and expects the result to be exact and bails if the directory headers suggest otherwise. And yes, I did consider making a "Holy Hand Granade of Antioch" reference, but consciously decided not to. Signed-off-by: David Oberhollenzer --- doc/format.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'doc/format.txt') diff --git a/doc/format.txt b/doc/format.txt index 41cba78..85a66dc 100644 --- a/doc/format.txt +++ b/doc/format.txt @@ -664,6 +664,11 @@ +------+--------------+------------------------------------------------------+ | u16 | file size | Total (uncompressed) size in bytes of the entry | | | | listing in the directory table, including headers. | + | | | | + | | | This value is 3 bytes larger than the real listing. | + | | | The Linux kernel creates "." and ".." entries for | + | | | offsets 0 and 1, and only after 3 looks into the | + | | | listing, subtracting 3 from the size. | +------+--------------+------------------------------------------------------+ | u16 | block offset | The (uncompressed) offset within the metadata block | | | | in the directory table where the directory listing | @@ -679,8 +684,8 @@ directory. I.e. a directory with N entries has at least N + 2 link count. - If the "file size" is set to 0, the directory is empty and there is no - corresponding listing in the directory table. + If the "file size" is set to a value < 4, the directory is empty and there is + no corresponding listing in the directory table. An extended directory can have a listing that is at most 4GiB in size, may -- cgit v1.2.3