Skip to content

squashfs bound decompressed block sizes - #459

Merged
deitch merged 1 commit into
diskfs:masterfrom
sap-nocops:limit_decompress
Nov 19, 2026
Merged

deitch merged 1 commit into
diskfs:masterfrom
sap-nocops:limit_decompress

Conversation

@sap-nocops

@sap-nocops sap-nocops commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Decompress every block into at most the size its kind allows: a metadata block into 8 KiB, a data or fragment block into the block size of the superblock.
A small, highly compressible block could otherwise expand without bound before any caller saw it.
Decompressors stop as soon as the limit is passed rather than decoding to the end, and fail with the new ErrDecompressedTooLarge.

Added a read option for zstd: WithZstdMaxMemory which sets the decoder history, in bytes, a zstd frame may ask for, by its window or as a single segment. A frame asking for more fails to decompress. The default, 8 MiB, reads the images of mksquashfs and of this package; a larger one reads frames compressed with a larger window, as zstd --long or --ultra may write, at the cost of as much memory per decompression. 0 keeps the default.

@sap-nocops
sap-nocops marked this pull request as draft November 18, 2026 15:46
@deitch

deitch commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

This is nice. I didn't think this could be an issue, but even if not, it is good to have. Why still draft?

@sap-nocops

Copy link
Copy Markdown
Contributor Author

need to make some changes to zstd, and also as is now. it could break some usages so I was thinking about introducing the limits with an option.

what do you think?

Thank you

@deitch

deitch commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

need to make some changes to zstd, and also as is now

OK, sure, can wait. This is OSS, and it is a go library, meaning people always can bind to specific hashes or semvers and not worry about breaking things. So if it is an improvement without breaking something, go for it.

thinking about introducing the limits with an option

What is the case where it could break something? Either the max size limit is correct, or it is not. If it is not correct, we should not introduce it; if it is correct, then anything that worked before was in error.

@sap-nocops
sap-nocops marked this pull request as ready for review November 19, 2026 10:46
@sap-nocops

Copy link
Copy Markdown
Contributor Author

ok so in the end I only kept the option to change the default value for zstd, Pr is now ready for review

deitch
deitch previously approved these changes Nov 19, 2026
@sap-nocops

Copy link
Copy Markdown
Contributor Author

add to re-push to address lint errors

@deitch
deitch merged commit 604a97e into diskfs:master Nov 19, 2026
20 checks passed
@sap-nocops
sap-nocops deleted the limit_decompress branch November 23, 2026 11:47
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.

2 participants