strukturag / libheif

libheif is an HEIF and AVIF file format decoder and encoder.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Encode then Decode Crash

dukesook opened this issue · comments

When heif_context* doesn't read from a file, HeifFile::m_input_stream never initialized. Therefore, calling heif_decode_image() results in an unexpected Segmentation Fault.

  // Read HEIF
  heif_context* ctx_read = heif_context_alloc();
  heif_context_read_from_file(ctx_read, filename, nullptr);

  heif_image_handle* handle;
  heif_context_get_primary_image_handle(ctx_read, &handle);

  heif_image* img;
  heif_decode_image(handle, &img, heif_colorspace_RGB, heif_chroma_interleaved_RGB, nullptr);

  // Write HEIF
  heif_encoder* encoder;
  heif_context* ctx_write = heif_context_alloc();
  heif_context_get_encoder_for_format(ctx_write, heif_compression_HEVC, &encoder);

  // 1. Encode image
  heif_context_encode_image(ctx_write, img, encoder, nullptr, &handle);

  // 2. Get image back
  heif_decode_image(handle, &img, heif_colorspace_RGB, heif_chroma_interleaved_RGB, nullptr); // SEGFAULT

I would like this to work, or at least have struct heif_error catch it.