cybersecurity · beginner · ~15 min · safe pentest lab
Recognise the gzip magic.
Detect a gzip-compressed blob from its magic bytes — firmware images are often gzip-wrapped and must be decompressed first.
Implement int is_gzip(const unsigned char *b) that returns 1 if the first two bytes are the gzip magic 0x1F 0x8B, else 0.
b: a byte buffer of at least 2 bytes. The grader passes a fixed buffer.Returns int: 1 if b[0] == 0x1F && b[1] == 0x8B, else 0.
b = 0x1F 0x8B 0x08 -> is_gzip(b) -> 1
b = 0x50 0x4B -> is_gzip(b) -> 0 (that is ZIP)
A byte buffer b of at least 2 bytes.
An int: 1 if the first two bytes are 0x1F 0x8B, else 0.
gzip magic is 0x1F 0x8B.
int is_gzip(const unsigned char *b) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.