-
Notifications
You must be signed in to change notification settings - Fork 7
Address edge-case for uncompressed data at end of LZXPRESS+huffman stream #75
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| length: int | ||
| symbol: int | ||
|
|
||
| HUFFMAN_BLOCK_SIZE = 65536 | ||
|
|
||
| def _read_16_bit(fh: BinaryIO) -> int: | ||
| return struct.unpack("<H", fh.read(2).rjust(2, b"\x00"))[0] | ||
|
|
@@ -147,11 +148,15 @@ | |
| bitstring = BitString() | ||
|
|
||
| while src.tell() - start_offset < size: | ||
| if size - (src.tell() - start_offset) <= 256: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a spec you can link to for this?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MS-XCA does not really talk about this case. Some other resources do take it into account and kind of mention it (linked below). Its not part of the Microsoft spec, so this edge-case might be a better fit in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of the code or README you link actually are relevant to what you're proposing to do here.
Are you actually fixing an algorithm bug or are you trying to work around an application bug (in the wrong place)? |
||
| dst.extend(src.read(size - (src.tell() - start_offset))) | ||
| return bytes(dst) | ||
|
|
||
| root = _build_tree(src.read(256)) | ||
| bitstring.init(src) | ||
|
|
||
| chunk_size = 0 | ||
| while chunk_size < 65536 and src.tell() - start_offset < size: | ||
| while chunk_size < HUFFMAN_BLOCK_SIZE and src.tell() - start_offset < size: | ||
| symbol = bitstring.decode(root) | ||
| if symbol < 256: | ||
| dst.append(symbol) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use a walrus operator here.