Skip to content

gzip: invalid length and checksum checks #19839

@Casper64

Description

@Casper64

Describe the bug

When decompressing a gzipped file of ~5KB the length and checksum verifications fail.

Reproduction Steps

module main

import compress.gzip
import os

fn main() {
	compressed := os.read_bytes('in.xml.gz')!
	println(compressed[0..100])

	decoded := gzip.decompress(compressed)!
	println(decoded.bytestr())
}

Expected Behavior

No errors

Current Behavior

V panic: result not set (length verification failed, got 4548, expected 3289448448)

Possible Solution

The decompression algorithm is correct, because when I remove the length and checksum check I can see that result is correct.

The following code seems to be overflowing/underflowing

(u32(data[data.len - 4]) << 24) | (u32(data[data.len - 3]) << 16) | (u32(data[data.len - 2]) << 8) | data[data.len - 1]

gzip.v

Additional Information/Context

No response

V version

0.4.2

Environment details (OS name and version, etc.)

V full version: V 0.4.2 25777bd.ad935ca
OS: Linux

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.Unit: vlibBugs/feature requests, that are related to the vlib.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions