Skip to content

Commit efb048c

Browse files
committed
FFmpeg decoder plugin: do not reference the exported heif_error_success object (#1854)
Dynamic plugins are compiled with LIBHEIF_EXPORTS, so inside plugin code LIBHEIF_API expands to __declspec(dllexport) on MSVC. Exported functions still resolve through the import library's jump thunks, but exported data has no thunk, and the reference to heif_error_success in the FFmpeg decoder and in nalu_utils.cc fails to link when the decoder is built as a plugin. On Linux this went unnoticed because the loader resolves the symbol from libheif at dlopen time. Use a file-local success object instead, as the other plugins do. nalu_utils.cc is compiled into both libheif and the plugin, so it gets its own local object rather than depending on heif_plugin.h. Fixes #1854
1 parent 72a2684 commit efb048c

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎libheif/plugins/decoder_ffmpeg.cc‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ extern "C"
4242
}
4343

4444

45+
// Plugins are compiled with LIBHEIF_EXPORTS, so on MSVC a reference to the exported
46+
// data object heif_error_success does not resolve against libheif (issue #1854).
47+
// Use a file-local success object instead.
48+
static const heif_error kSuccess = {heif_error_Ok, heif_suberror_Unspecified, "Success"};
49+
4550
struct ffmpeg_decoder
4651
{
4752
// --- input data
@@ -198,7 +203,7 @@ static heif_error ffmpeg_new_decoder2(void** dec, const heif_decoder_plugin_opti
198203
}
199204

200205

201-
return heif_error_success;
206+
return kSuccess;
202207
}
203208

204209
static heif_error ffmpeg_new_decoder(void** dec)
@@ -333,7 +338,7 @@ static heif_error ffmpeg_push_data2(void *decoder_raw, const void *data, size_t
333338

334339
decoder->input_data.emplace_back(std::move(pkt));
335340

336-
return heif_error_success;
341+
return kSuccess;
337342
}
338343

339344
static heif_error ffmpeg_push_data(void *decoder_raw, const void *data, size_t size)
@@ -607,7 +612,7 @@ static heif_error ffmpeg_av_decode(ffmpeg_decoder* decoder, AVCodecContext* av_d
607612
av_frame->width, av_frame->height, shift, byte_swap);
608613
}
609614

610-
return heif_error_success;
615+
return kSuccess;
611616
}
612617

613618
heif_chroma chroma = ffmpeg_get_chroma_format(pix_fmt);
@@ -680,7 +685,7 @@ static heif_error ffmpeg_av_decode(ffmpeg_decoder* decoder, AVCodecContext* av_d
680685
w, h, shift, byte_swap);
681686
}
682687

683-
return heif_error_success;
688+
return kSuccess;
684689
}
685690
else {
686691
const char* fmt_name = av_get_pix_fmt_name(static_cast<AVPixelFormat>(av_frame->format));
@@ -707,7 +712,7 @@ static heif_error ffmpeg_decode_next_image2(void* decoder_raw,
707712
heif_color_profile_nclx* nclx = NULL;
708713
int ret = 0;
709714

710-
heif_error err = heif_error_success;
715+
heif_error err = kSuccess;
711716

712717
if (!decoder->input_data.empty()) {
713718
uint8_t* parse_av_data = NULL;

‎libheif/plugins/nalu_utils.cc‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
#include <utility>
2424
#include "nalu_utils.h"
2525

26+
// Plugins are compiled with LIBHEIF_EXPORTS, so on MSVC a reference to the exported
27+
// data object heif_error_success does not resolve against libheif (issue #1854).
28+
// Use a file-local success object instead.
29+
static const heif_error kSuccess = {heif_error_Ok, heif_suberror_Unspecified, "Success"};
30+
2631
NalUnit::NalUnit()
2732
{
2833
nal_data_ptr = NULL;
@@ -91,7 +96,7 @@ const heif_error NalMap::parseHevcNalu(const uint8_t *cdata, size_t size)
9196
ptr += nal_size;
9297
}
9398

94-
return heif_error_success;
99+
return kSuccess;
95100
}
96101

97102
void NalMap::clear() { map.clear(); }

0 commit comments

Comments
 (0)