Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compress/bzip2: read of zero bytes yields error #22028

Closed
rogpeppe opened this issue Sep 25, 2017 · 3 comments
Closed

compress/bzip2: read of zero bytes yields error #22028

rogpeppe opened this issue Sep 25, 2017 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rogpeppe
Copy link
Contributor

go version devel +6171d05 Sat Sep 23 09:24:02 2017 +0000 linux/amd64

The following program prints:

bzip2 data invalid: block checksum mismatch

but it should not.

package main

import (
	"bytes"
	"compress/bzip2"
	"log"
)

var data = []byte{
	0x42, 0x5a, 0x68, 0x39, 0x31, 0x41, 0x59, 0x26, 0x53, 0x59, 0x36, 0xa9,
	0xc3, 0x7a, 0x00, 0x00, 0x9a, 0xfb, 0x84, 0xc0, 0x80, 0x00, 0x80, 0x40,
	0x00, 0xff, 0x80, 0x00, 0x22, 0x62, 0xe0, 0x1e, 0x00, 0x00, 0x01, 0x10,
	0x08, 0x20, 0x00, 0x94, 0x82, 0xaa, 0x32, 0x93, 0x35, 0x06, 0x8d, 0x36,
	0xa0, 0xd3, 0x20, 0x92, 0x49, 0xea, 0x69, 0xa0, 0xd0, 0x00, 0x33, 0xb3,
	0xc8, 0xe5, 0x27, 0xa0, 0x20, 0x68, 0x88, 0x48, 0x71, 0xc1, 0xa7, 0x02,
	0x43, 0x0e, 0x18, 0x0c, 0x24, 0x10, 0x18, 0x83, 0x64, 0x36, 0x4e, 0x46,
	0x8c, 0x4a, 0x6b, 0x7c, 0x94, 0x92, 0xaa, 0x9a, 0x55, 0x08, 0x82, 0xe8,
	0xa6, 0x33, 0x6b, 0x4f, 0x2a, 0x2f, 0x09, 0x4a, 0x33, 0x85, 0xb0, 0x45,
	0x8b, 0x98, 0x51, 0xaa, 0xab, 0xbe, 0x93, 0xa1, 0xc7, 0x1b, 0xbf, 0x29,
	0xbd, 0x1c, 0x3d, 0x5f, 0xd0, 0x98, 0x90, 0x54, 0x5d, 0xc9, 0x14, 0xe1,
	0x42, 0x40, 0xda, 0xa7, 0x0d, 0xe8,
}

func main() {
	r := bzip2.NewReader(bytes.NewReader(data))
	_, err := r.Read(nil)
	if err != nil {
		log.Fatal(err)
	}
}
@dsnet dsnet self-assigned this Sep 25, 2017
@dsnet dsnet added this to the Go1.10 milestone Sep 25, 2017
@gopherbot
Copy link

Change https://golang.org/cl/66110 mentions this issue: compress/bzip2: fix checksum mismatch on empty reads

@dsnet
Copy link
Member

dsnet commented Sep 25, 2017

Thanks for the succinct report.

@gopherbot
Copy link

Change https://golang.org/cl/66111 mentions this issue: archive/tar: avoid empty IO operations

@dsnet dsnet added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 25, 2017
gopherbot pushed a commit that referenced this issue Sep 25, 2017
The interfaces for io.Reader and io.Writer permit calling Read/Write
with an empty buffer. However, this condition is often not well tested
and can lead to bugs in various implementations of io.Reader and io.Writer.
For example, see #22028 for buggy io.Reader in the bzip2 package.

We reduce the likelihood of hitting these bugs by adjusting
regFileReader.Read and regFileWriter.Write to avoid performing
Read and Write calls when the buffer is known to be empty.

Fixes #22029

Change-Id: Ie4a26be53cf87bc4d2abd951fa005db5871cc75c
Reviewed-on: https://go-review.googlesource.com/66111
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Giovanni Bajo <rasky@develer.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Sep 25, 2018
@rsc rsc unassigned dsnet Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants