Skip to content

Commit

Permalink
Merge pull request #32 from alexrsagen/patch-1
Browse files Browse the repository at this point in the history
Add range check to NewDecoder
  • Loading branch information
brian-armstrong-discord authored May 1, 2018
2 parents bab63a0 + 8e743c1 commit 66f82ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 9 additions & 3 deletions lilliput.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
)

var (
ErrInvalidImage = errors.New("unrecognized image format")
ErrDecodingFailed = errors.New("failed to decode image")
ErrBufTooSmall = errors.New("buffer too small to hold image")
ErrInvalidImage = errors.New("unrecognized image format")
ErrDecodingFailed = errors.New("failed to decode image")
ErrBufTooSmall = errors.New("buffer too small to hold image")
ErrFrameBufNoPixels = errors.New("Framebuffer contains no pixels")

gif87Magic = []byte("GIF87a")
gif89Magic = []byte("GIF89a")
Expand Down Expand Up @@ -59,6 +60,11 @@ func isGIF(maybeGIF []byte) bool {
// image data provided in buf. If the first few bytes of buf do not
// point to a valid magic string, an error will be returned.
func NewDecoder(buf []byte) (Decoder, error) {
// Check buffer length before accessing it
if len(buf) == 0 {
return nil, ErrInvalidImage
}

isBufGIF := isGIF(buf)
if isBufGIF {
return newGifDecoder(buf)
Expand Down
3 changes: 1 addition & 2 deletions opencv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package lilliput
import "C"

import (
"errors"
"io"
"time"
"unsafe"
Expand Down Expand Up @@ -173,7 +172,7 @@ func (f *Framebuffer) ResizeTo(width, height int, dst *Framebuffer) error {
// not large enough to hold the given dimensions.
func (f *Framebuffer) Fit(width, height int, dst *Framebuffer) error {
if f.mat == nil {
return errors.New("Framebuffer contains no pixels")
return ErrFrameBufNoPixels
}

aspectIn := float64(f.width) / float64(f.height)
Expand Down

0 comments on commit 66f82ac

Please sign in to comment.