vips icon indicating copy to clipboard operation
vips copied to clipboard

Bindings will hard crash on invalid color space

Open dave-andersen opened this issue 10 years ago • 4 comments

The attached patch addresses this crash, which happens with specific ill-formed jpegs.

diff --git a/vips.go b/vips.go
index 36118e1..14cd90a 100644
--- a/vips.go
+++ b/vips.go
@@ -311,6 +311,10 @@ func Resize(buf []byte, o Options) ([]byte, error) {
        C.vips_colourspace_0(image, &tmpImage, C.VIPS_INTERPRETATION_sRGB)
        C.g_object_unref(C.gpointer(image))
        image = tmpImage
+       if image == nil {
+               debug("colourspace conversion failed")
+               return nil, resizeError()
+       }

        // Finally save
        length := C.size_t(0)

dave-andersen avatar May 30 '15 00:05 dave-andersen

Thank you! I'll apply the patch asap.

DAddYE avatar Jun 01 '15 16:06 DAddYE

I think it would probably be safer to test the exit status of vips_colourspace(). It will return 0 for success, -1 for failure.

jcupitt avatar Jun 07 '15 22:06 jcupitt

Thanks @jcupitt

DAddYE avatar Jun 08 '15 16:06 DAddYE

Will this be patched? I seem to have hit the same problem.

eriken avatar Feb 19 '16 14:02 eriken