I dont even...

It turns out passing a negative header size to the zlib init function
makes it behave in the correct way. Hours wasted, but at least it works now.