-
-
Notifications
You must be signed in to change notification settings - Fork 9
read coding tables in one go if there is sufficient input #90
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 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1009,9 +1009,40 @@ | |||||||||||||||||||||||||||||
| s.selector[i] = pos[0]; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| t = 0; | ||||||||||||||||||||||||||||||
| current_block = Block35; | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| // try to read the coding tables in one go if there is sufficient input | ||||||||||||||||||||||||||||||
| let bits_needed = | ||||||||||||||||||||||||||||||
| usize::from(nGroups) * (5 + (usize::from(alphaSize) * 2 * 20)); | ||||||||||||||||||||||||||||||
| let bytes_needed = bits_needed.div_ceil(8); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if strm.avail_in as usize >= bytes_needed { | ||||||||||||||||||||||||||||||
| for t in 0..usize::from(nGroups) { | ||||||||||||||||||||||||||||||
| let mut curr = GET_BITS!(strm, s, 5); | ||||||||||||||||||||||||||||||
| for i in 0..usize::from(alphaSize) { | ||||||||||||||||||||||||||||||
| loop { | ||||||||||||||||||||||||||||||
| if !(1..=20).contains(&curr) { | ||||||||||||||||||||||||||||||
| error!(BZ_DATA_ERROR); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| if !GET_BIT!(strm, s) { | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| match GET_BIT!(strm, s) { | ||||||||||||||||||||||||||||||
| false => curr += 1, | ||||||||||||||||||||||||||||||
| true => curr -= 1, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| s.len[t][i] = curr as u8; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Collaborator
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. What code is this block based on?
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. this bit of C code Lines 322 to 335 in d5d181b
it's all scattered around in our implementation here, but if we assume sufficient input, we can basically copy the C code. |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| t = nGroups; | ||||||||||||||||||||||||||||||
| current_block = Block35; | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||
| t = 0; | ||||||||||||||||||||||||||||||
| current_block = Block35; | ||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| Block18 => { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
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.
it should be possible to bound this loop (I think it's 20 bits of code at most, so 40bits total?). But it's hard to be confident
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.
I fuzzed this for many hours using this size of 20. So it holds at least for files encoded using the current version (which uses 17 bits at most, while earlier bzip2 versions used up to 20 bits).