molnarg / ascii-zip

A deflate compressor that emits compressed data that is in the [A-Za-z0-9] ASCII byte range.
170 stars 25 forks source link

Variable scoping #1

Open floyd-fuh opened 4 years ago

floyd-fuh commented 4 years ago

I created a new brute-force mode for the tool (it is not pretty yet as it simply works but is a huge hack). I was able to find what I did (a deflated stream that includes the string "5#"), however, there were many issues and the ASCIICompressor code throws a couple of exceptions:

https://github.com/floyd-fuh/ascii-zip/commit/b181fe814000cd2bc49a1125d40cc09286da7f26

So I'm generally a little confused about the scope of your variables, for example "huffman". It is set here (but due to python's scoping, will live in the function as variable if I got that right): https://github.com/molnarg/ascii-zip/blob/master/compress.py#L67 . But of course if "cursor" was below 0, the variable is still uninitialized. Something similar happens on https://github.com/molnarg/ascii-zip/blob/master/compress.py#L81 . But then you just use the maybe-uninitialized variable "huffman" here https://github.com/molnarg/ascii-zip/blob/master/compress.py#L96 .

This is all problematic as some of the functions actually return None, such as here: https://github.com/molnarg/ascii-zip/blob/master/compress.py#L139 or https://github.com/molnarg/ascii-zip/blob/master/compress.py#L159

I'm not enough into the topic of the deflate algorithm, so it is hard for me to fully undestand the code and fix it. Any chance you'll have a look?

molnarg commented 4 years ago

Hey, sorry I didn’t take a look at this code in the past five years, so you probably know it better than me at this point.