There is definitely a bug in that patch, and that is that QCOW2_COMPRESSED_SECTOR_MASK is an unsigned int instead of a uint64_t (so the mask is too small).
It looks like the bug has existed in some places before that patch (because they use ~511 as a mask), but not in others.
This would explain why the bug is visible only for some images, namely for those with a compressed size of more than 4 GB, I presume.
And indeed, fixing QCOW2_COMPRESSED_SECTOR_MASK to be an unsigned long long fixes the bug. I’ll send a patch (but I’ll have to write a more simple and quicker test case first).
There is definitely a bug in that patch, and that is that QCOW2_COMPRESSE D_SECTOR_ MASK is an unsigned int instead of a uint64_t (so the mask is too small).
It looks like the bug has existed in some places before that patch (because they use ~511 as a mask), but not in others.
This would explain why the bug is visible only for some images, namely for those with a compressed size of more than 4 GB, I presume.
And indeed, fixing QCOW2_COMPRESSE D_SECTOR_ MASK to be an unsigned long long fixes the bug. I’ll send a patch (but I’ll have to write a more simple and quicker test case first).
Max