Skip to content

Commit

Permalink
Check last error after getting blob, before calling conversions (refs #…
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfx committed Apr 3, 2024
1 parent 760c816 commit 8a7c940
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions imagick/magick_wand_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,9 @@ func (mw *MagickWand) GetImageBlob() []byte {
clen := C.size_t(0)
csblob := C.MagickGetImageBlob(mw.mw, &clen)
defer relinquishMemory(unsafe.Pointer(csblob))
if err := mw.GetLastError(); err != nil {
return nil
}
ret := C.GoBytes(unsafe.Pointer(csblob), C.int(clen))
runtime.KeepAlive(mw)
return ret
Expand All @@ -957,6 +960,9 @@ func (mw *MagickWand) GetImagesBlob() []byte {
clen := C.size_t(0)
csblob := C.MagickGetImagesBlob(mw.mw, &clen)
defer relinquishMemory(unsafe.Pointer(csblob))
if err := mw.GetLastError(); err != nil {
return nil
}
runtime.KeepAlive(mw)
return C.GoBytes(unsafe.Pointer(csblob), C.int(clen))
}
Expand Down
8 changes: 7 additions & 1 deletion imagick/magick_wand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,14 @@ func TestReadImageBlob(t *testing.T) {

mw := NewMagickWand()

// Try to read an empty wand
blob := mw.GetImageBlob()
if blob != nil {
t.Fatal("Expected nil blob on invalid wand")
}

// Read an invalid blob
blob := []byte{}
blob = []byte{}
if err := mw.ReadImageBlob(blob); err == nil {
t.Fatal("Expected a failure when passing a zero length blob")
}
Expand Down

0 comments on commit 8a7c940

Please sign in to comment.