unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.59k stars 253 forks source link

[BUG] extractor/text.go func1 - panic: runtime error: slice bounds out of range [:2] with capacity 1 #310

Closed gunnsth closed 4 years ago

gunnsth commented 4 years ago

Description

A crash was discovered while fuzzing.

Expected Behavior

Expect fuzz function to execute through without crashes or timeouts.

Actual Behavior

Steps to reproduce the behavior:

  1. Run the fuzz function on the provided snippet.
  2. View crash message.
Unlicensed copy of unidoc
To get rid of the watermark - Please get a license on https://unidoc.io
panic: runtime error: slice bounds out of range [:2] with capacity 1

goroutine 1 [running]:
github.com/unidoc/unipdf/v3/extractor.(*Extractor).extractPageText.func1(0xc000260ed0, 0xb2ed40, 0x118f418, 0xb2ed40, 0x118f418, 0x9f7400, 0xc000029760, 0x9f7400, 0xc000029768, 0x3ff0000000000000, ...)
        /go/pkg/mod/github.com/unidoc/unipdf/v3@v3.6.2-0.20200415193336-ff79a9b1bdc2/extractor/text.go:198 +0x52a9
github.com/unidoc/unipdf/v3/contentstream.(*ContentStreamProcessor).Process(0xc00014fc28, 0xc000130cf0, 0x0, 0x0)
        /go/pkg/mod/github.com/unidoc/unipdf/v3@v3.6.2-0.20200415193336-ff79a9b1bdc2/contentstream/processor.go:277 +0x834
github.com/unidoc/unipdf/v3/extractor.(*Extractor).extractPageText(0xc000060840, 0xc000029734, 0x2, 0xc000130cf0, 0x0, 0x7f5349c32108, 0x0, 0xc000029734, 0x11655c0, 0x7f5349c32108)
        /go/pkg/mod/github.com/unidoc/unipdf/v3@v3.6.2-0.20200415193336-ff79a9b1bdc2/extractor/text.go:351 +0x6c3
github.com/unidoc/unipdf/v3/extractor.(*Extractor).ExtractPageText(0xc000060840, 0x40ed9d, 0xa42260, 0xc000260e70, 0xc00014fe08, 0x984edc)
        /go/pkg/mod/github.com/unidoc/unipdf/v3@v3.6.2-0.20200415193336-ff79a9b1bdc2/extractor/text.go:50 +0x6d
github.com/unidoc/unipdf/v3/extractor.(*Extractor).ExtractTextWithStats(0xc000060840, 0xc000060840, 0x0, 0x0, 0x0, 0x0, 0x5)
        /go/pkg/mod/github.com/unidoc/unipdf/v3@v3.6.2-0.20200415193336-ff79a9b1bdc2/extractor/text.go:41 +0x4a
github.com/unidoc/unipdf/v3/extractor.(*Extractor).ExtractText(...)
        /go/pkg/mod/github.com/unidoc/unipdf/v3@v3.6.2-0.20200415193336-ff79a9b1bdc2/extractor/text.go:34
unipdf-fuzz.fuzzExtractText(0x7f5320c3d000, 0x124, 0x124, 0x1)
        /fuzz/fuzz.go:116 +0x227
unipdf-fuzz.Fuzz(0x7f5320c3d000, 0x124, 0x124, 0x3)
        /fuzz/fuzz.go:133 +0x117
go-fuzz-dep.Main(0xc00014ff70, 0x1, 0x1)
        go-fuzz-dep/main.go:36 +0x1ad
main.main()
        unipdf-fuzz/go.fuzz.main/main.go:15 +0x52
exit status 2

Attachments

PDF from fuzz corpus: 0ba5eb94a9c103b7088ca791a4e031bb55de220d Code: fuzz.go