Closed
Description
Bug report
Saving a heif image to a custom target segfaults when the "write" callback returns -1
(writer closed).
To Reproduce
Steps to reproduce the behavior:
#include <stdio.h>
#include <vips/vips.h>
static gint64 target_write ( VipsTargetCustom *target_custom, gpointer buffer, gint64 length, gpointer target_ptr )
{
return -1; // always return -1
}
int
main(int argc, char **argv)
{
VipsImage *in;
VipsTargetCustom *target;
VipsImage *out;
int code;
if (VIPS_INIT(argv[0]))
vips_error_exit(NULL);
if (argc != 2)
vips_error_exit("usage: %s infile", argv[0]);
if (!(in = vips_image_new_from_file(argv[1], NULL)))
vips_error_exit(NULL);
target = vips_target_custom_new();
g_signal_connect( target, "write", G_CALLBACK(target_write), NULL );
code = vips_heifsave_target(in, (VipsTarget *) target, NULL);
return code;
}
Expected behavior
Program should not crash. Instead a proper error code should be returned, as it does when using vips_jpegsave_target
.
Actual behavior
Segmentation fault: 11
Screenshots
bash-3.2$ gcc `pkg-config --cflags glib-2.0` heif.c `pkg-config --libs glib-2.0` -lglib-2.0 -lvips -lgobject-2.0
bash-3.2$ ./a.out tif.tif
Segmentation fault: 11
Environment
(please complete the following information)
- OS: MacOS Ventura 13.4.1
- Vips: 8.14.3
Additional context
I discovered the issue when adding streaming support to the govips
library: davidbyttow/govips#370 (comment)