------- Comment From i...@de.ibm.com 2024-10-07 10:58 EDT-------
I've extracted the compression logic into a stand-alone script, and it doesn't 
fail:

#!/usr/bin/env python3
import gzip
import struct
import zlib

value = b"ABABABABABABABABABAB\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Z"
compressed = b"\037\213\010\010\000\000\000\000\002\377File\000"
bc = zlib.compressobj(6, zlib.DEFLATED, -zlib.MAX_WBITS, zlib.DEF_MEM_LEVEL, 0)
compressed += bc.compress(value)
compressed += bc.flush()
compressed += struct.pack("<L", zlib.crc32(value) & 0xFFFFFFFF)
compressed += struct.pack("<L", len(value) & 0xFFFFFFFF)
print(compressed)
assert gzip.decompress(compressed) == value

I think the problem is rather here:

@staticmethod
def _write_binary_item_base64_encoded(
[...]
for chunk in chunks:
file.write(b"\n ")
file.write(base64.b64encode(chunk))

Example:

>>> base64.b64decode(base64.b64encode(b"a")+base64.b64encode(b"b"))
b'a'

Sometimes this works though:

>>> base64.b64decode(base64.b64encode(b"aaa")+base64.b64encode(b"b"))
b'aaab'

Seems like s390x was unlucky and hit the problematic case. I would
suggest to call b64decode() on each line individually.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2076269

Title:
  invalid base64 encoded gzip data on s390x causes autopkgtest failures

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu-z-systems/+bug/2076269/+subscriptions


-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to