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

index/suffixarray: Index.Read and Index.Write result abnormal and panic. #33751

Closed
3ks opened this issue Aug 21, 2019 · 2 comments
Closed

index/suffixarray: Index.Read and Index.Write result abnormal and panic. #33751

3ks opened this issue Aug 21, 2019 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@3ks
Copy link

3ks commented Aug 21, 2019

What version of Go are you using (go version)?

go version go1.12.5 windows/amd64

Does this issue reproduce with the latest release?

yes (at least the go playground is yes.)

What operating system and processor architecture are you using (go env)?

go env Output
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\35707\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\codes\go
set GOPROXY=https://mirrors.aliyun.com/goproxy/
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\35707\AppData\Local\Temp\go-build997738542=/tmp/go-build -gno-record-gcc-switches

What did you do?

The Go Playground

run code:
package main

import (
	"bytes"
	"fmt"
	"index/suffixarray"
)

func main() {
	b:=[]byte("zyx")
	i:=suffixarray.New(b)
	fmt.Println("bytes before:",string(i.Bytes()))

	bf:=bytes.NewBufferString("zabcdefghijklmnopqrstuvwxyz")
	err:= i.Read(bf)
	if err!=nil{
		fmt.Println("read_err:",err)
	}
	fmt.Println("bytes after:",string(i.Bytes()))

	bf2:=bytes.Buffer{}
	err2:=i.Write(&bf2)
	if err2!=nil{
		fmt.Println("write_err:",err2)
	}
	fmt.Println("bf2.String:",bf2.String())
}

What did you expect to see?

bytes before: zyx
bytes after: zyxzabcdefghijklmnopqrstuvwxyz
bf2.String: zyxzabcdefghijklmnopqrstuvwxyz

What did you see instead?

bytes before: zyx
read_err: unexpected EOF
bytes after: jklmnopqrstuvwxyz
bf2.String: z         jklmnopqrstuvwxyz
   �╔

Panic

The Go Playground

If the buffer value is :
// bf:=bytes.NewBufferString("zabcdefghijklmnopqrstuvwxyz") // above code
bf:=bytes.NewBufferString("abcdefghijklmnopqrstuvwxyz")  // del the first letter 'z'
Output:
bytes before: zyx
panic: runtime error: makeslice: len out of range

goroutine 1 [running]:
index/suffixarray.(*Index).Read(0xc000089f58, 0x4e5720, 0xc000076360, 0xc00005e1
a0, 0x1a)
        C:/Go/src/index/suffixarray/suffixarray.go:112 +0xe9
main.main()
        C:/Users/35707/.GoLand2019.2/config/scratches/example.go:15 +0x23d

Process finished with exit code 2

In the end

Is the lib bug or mine error? Thanks for your help!

@agnivade agnivade changed the title suffixarray: Index.Read and Index.Write result abnormal and panic. index/suffixarray: Index.Read and Index.Write result abnormal and panic. Aug 21, 2019
@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 21, 2019
@agnivade
Copy link
Contributor

@griesemer

@griesemer
Copy link
Contributor

  1. Whatever the bug in index/suffixarray was, this appears to have been fixed. With Go 1.13 I see for the 1st program:
$ go run x.go
bytes before: zyx
read_err: unexpected EOF
bytes after: jklmnopqrstuvwxyz
bf2.String: zjklmnopqrstuvwxyz?

and for the 2nd program:

$ go run x.go
bytes before: zyx
read_err: suffixarray: data too large
bytes after: zyx
bf2.String: zyx
  1. I don't know if these programs were created only to expose the crash or not. But as is they don't make much sense except for exposing the crash. suffixarray.Index.Read is expected to read a (previously written, using suffixarray.Index.Write) suffix array index, not just some random data.

Given that the crash was fixed, the remaining errors are clearly programmer errors. For instance, the error read_err: suffixarray: data too large is due to the fact that the read data wasn't written using suffixarray.Index.Write and thus has an incorrect format.

Before reporting a bug in the std lib, please try the latest version if at all possible and see if the problem still exists. Thanks.

Closing.

@golang golang locked and limited conversation to collaborators Aug 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants