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 54cc04d commit c0ff8ec
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 @@ -1125,6 +1125,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 @@ -1140,6 +1143,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 @@ -183,8 +183,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 c0ff8ec

Please sign in to comment.