NeRdTheNed / deft4j

WIP deflate toolkit for Java
BSD Zero Clause License
7 stars 0 forks source link

Optimise distance length 258 edge case #3

Open NeRdTheNed opened 1 year ago

NeRdTheNed commented 1 year ago

Distance codes with a length of 258 are usually encoded with code 285. However, it's technically possible to encode these with code 284, as a length of 227 (base length) + 31 (extra bits). This may not be legal according to the Deflate specification, and it's not considered good practice (Mark Adler has stated "In any case, a self-respecting deflate compressor should never produce [this code]."). deft4j currently misses two optimisations related to this:

See #1 for previous discussion.

ace-dent commented 1 year ago

Perhaps add the parameter switch -cautious (vs -reckless!) to cover this stricter conformance and for #2 ?

NeRdTheNed commented 1 year ago

Perhaps add the parameter switch -cautious (vs -reckless!) to cover this stricter conformance and for #2 ?

I think options like that would be a good idea. I might keep these two optimisations behind seperate switches, because issues related to #2 are from decoders which can't decode certain valid deflate streams, while issues related to this would be from creating possibly standard non-compliant streams.