From abd6679f58dc7d22a7ab9b3c5e9eff0edb25c62e Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Tue, 7 Apr 2015 23:28:38 +0200 Subject: [PATCH] feat(#19): maximum image size --- options.go | 5 ++++- vips.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/options.go b/options.go index 7b55734..d93cfaa 100644 --- a/options.go +++ b/options.go @@ -6,7 +6,10 @@ package bimg */ import "C" -const QUALITY = 80 +const ( + QUALITY = 80 + MAX_SIZE = 16383 +) type Gravity int diff --git a/vips.go b/vips.go index fbd7b80..33f8933 100644 --- a/vips.go +++ b/vips.go @@ -113,6 +113,10 @@ func vipsExtract(image *C.struct__VipsImage, left, top, width, height int) (*C.s var buf *C.struct__VipsImage defer C.g_object_unref(C.gpointer(image)) + if width > MAX_SIZE || height > MAX_SIZE { + return nil, errors.New("Maximum image size exceeded") + } + err := C.vips_extract_area_bridge(image, &buf, C.int(left), C.int(top), C.int(width), C.int(height)) if err != 0 { return nil, catchVipsError()