Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squashfs: fix error format when file larger than block size #287

Merged
merged 5 commits into from
Mar 10, 2025

Conversation

Xynnn007
Copy link
Contributor

@Xynnn007 Xynnn007 commented Mar 7, 2025

https://dr-emann.github.io/squashfs/squashfs.html#_file_inodes

Due to SquashFS spec, file inode's 'blocks start' field means the offset from the beginning of the file.

This commit also fixes the fragmentData location calculation.

Finally, due to Spec, if a file does not have fragment data, its frag index should be all 0xF.

Fixes #282

@Xynnn007
Copy link
Contributor Author

@deitch Hey, now it passes with your test case, so I include the 2 test commits

@deitch
Copy link
Collaborator

deitch commented Mar 10, 2025

I really would have enjoyed having you around when I was trying to figure out how squashfs worked under the covers. Happy to have you now, though.

Can you rebase this on master, so it includes just your changes, not the first 2 commits?

Due to SquashFS, the first field of both File inode and extended file
inode is called 'blocks start', that means

```
The offset from the start of the archive to the first data block.
```

Link https://dr-emann.github.io/squashfs/squashfs.html#_file_inodes

Signed-off-by: Xynnn007 <[email protected]>
The granularity of fragment data writing is block, so we don't need to
return an unaligned fragment amount but 'sized chunks'

everytime we write a fragmentdata block, the variable location should be
added with a size of 'blocksize', which means that we have written a new
fragment block.

The variable `location` will be reused to tell new accumulated
fragmentblocks position.

Signed-off-by: Xynnn007 <[email protected]>
The variable fragmentData is used to record if the current fragment data
is enough to occupy a block. Once a block is written, it should be
cleared for a new round of loop.

Signed-off-by: Xynnn007 <[email protected]>
Due to spec, frag index of file inode

https://dr-emann.github.io/squashfs/squashfs.html#_file_inodes

```
An index into the Fragment Table which describes the fragment block
that the tail end of this file is stored in. If not used, this is set
to 0xFFFFFFFF.
```

Signed-off-by: Xynnn007 <[email protected]>
@Xynnn007
Copy link
Contributor Author

Rebased.

@deitch deitch merged commit 6e6c2a9 into diskfs:master Mar 10, 2025
20 checks passed
@deitch
Copy link
Collaborator

deitch commented Mar 10, 2025

Great, thanks. I will rebase my test on it.

@Xynnn007 Xynnn007 deleted the fix-offset branch March 10, 2025 14:20
@Xynnn007
Copy link
Contributor Author

@deitch Shall we cut another release for this? We downstream can depend on the bug fix

@deitch
Copy link
Collaborator

deitch commented Mar 10, 2025

Sure.

@deitch
Copy link
Collaborator

deitch commented Mar 10, 2025

What do you use it for downstream?

@deitch
Copy link
Collaborator

deitch commented Mar 10, 2025

v1.5.2 on its way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SquashFS reading is not consistent with writing for large writing
2 participants