I'm trying to design an algorithm that decompresses a file that can be in gzip or tar formats as a solution to this CTF challenge. The whole game is designed to be solved with Linux commands but I decided to go my way with Python, so the challenge solution was tested before. Back to the problem though, the starting file has a 1F 8B 08 file signature that I confirmed by reading it with a short script in Python REPL which means that I ought to use Python gzip to decompress it, however calling gzip.decompress(my_file_contents) returns an empty by string b''. I also tried to follow this Stack Overflow answer but it didn't work. What confuses me about gzip.open is that reading the contents shows a different string to the original one and the signature changes to something that's not listed as a file signature. What am I doing wrong? Does Python file decompression work in a specific way I should learn?
REPL
>>> import gzip
>>> with open("decompress/start", "rb") as r:
... print(r.read())
...
b'\x1f\x8b\x08\x08\xdf\xcd\xebf\x02\x03data2.bin\x00\x01>\x02\xc1\xfdBZh91AY&SY\xca\x83\xb2\xc1\x00\x00\x17\x7f\xff\xdf\xf3\xf4\xa7\xfc\x9f\xfe\xfe\xf2\xf3\xcf\xfe\xf5\xff\
>>> with gzip.open("decompress/start", "rb") as r:
... print(r.read())
...
b'BZh91AY&SY\xca\x83\xb2\xc1\x00\x00\x17\x7f\xff\xdf\xf3\xf4\xa7\xfc\x9f\xfe\xfe\xf2\xf3\xcf\xfe\xf5\xff\xff\xdd\xbf~[\xfe\xfa\xff\xdf\xbe\x97\xaao\xff\xf0\xde\xed\xf7\xb0\
>>>
I would've liked to give you guys a minimal reproducible code snippet but this is a file stored in the CTF server that needs a password, if I give you that password I would give you a spoiler.