FWIW it was immediately clear to me why you needed to scale the buffer by some factor to account for increased size upon decompression.