phin1x / go-ipp

Pure Go IPP library
Apache License 2.0
138 stars 35 forks source link

panic: runtime error: makeslice: len out of range #16

Closed pax0 closed 4 years ago

pax0 commented 4 years ago

The length returned by the readValueLength function in attribute.go is negative in some cases, resulting in an error in make in the decodeString function

Error info:

panic: runtime error: makeslice: len out of range

goroutine 15 [running]: github.com/phin1x/go-ipp.(AttributeDecoder).decodeString(0xc00051fc10, 0xc000016a00, 0x200a, 0x0, 0x0) /root/go/pkg/mod/github.com/phin1x/go-ipp@v1.5.0/attribute.go:456 +0xc5 github.com/phin1x/go-ipp.(AttributeDecoder).Decode(0xc00004cc10, 0xc000428518, 0x1, 0x1, 0x1) /root/go/pkg/mod/github.com/phin1x/go-ipp@v1.5.0/attribute.go:411 +0x163 github.com/phin1x/go-ipp.(*RequestDecoder).Decode(0xc00051fc80, 0x818e80, 0xc000072bd0, 0x8, 0xc00004cbe8, 0x6ada57) /root/go/pkg/mod/github.com/phin1x/go-ipp@v1.5.0/request.go:201 +0x331

pax0 commented 4 years ago

Problem causes: Caused by *data = int16(order.Uint16(bs)) in the binary.Read function. Unsigned type and signed type conversion problem

Test code: var a uint16 = 1 << 16 - 1234 fmt.Println(a, int16(a))

Resoult: 64302 -1234

phin1x commented 4 years ago

The binary package is part of the golang standard library. Please report the issue to the upstream golang github project.