Skip to content

Commit 6c34f43

Browse files
fancycodefarindk
authored andcommitted
Wait for decoding jobs to finish before returning.
If an early job returns an error and the method returns, the remaining jobs continue to run and might try to access objects that no longer exist.
1 parent cf80c7a commit 6c34f43

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

libheif/image-items/grid.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ Result<std::shared_ptr<HeifPixelImage>> ImageItem_Grid::decode_compressed_image(
227227
}
228228
}
229229

230+
#if ENABLE_PARALLEL_TILE_DECODING
231+
static void wait_for_jobs(std::deque<std::future<Error> >* jobs) {
232+
if (jobs->empty()) {
233+
return;
234+
}
235+
236+
while (!jobs->empty()) {
237+
jobs->front().get();
238+
jobs->pop_front();
239+
}
240+
}
241+
#endif
230242

231243
Result<std::shared_ptr<HeifPixelImage>> ImageItem_Grid::decode_full_grid_image(const heif_decoding_options& options) const
232244
{
@@ -372,11 +384,11 @@ Result<std::shared_ptr<HeifPixelImage>> ImageItem_Grid::decode_full_grid_image(c
372384

373385
if (errs.size() >= (size_t) get_context()->get_max_decoding_threads()) {
374386
Error e = errs.front().get();
387+
errs.pop_front();
375388
if (e) {
389+
wait_for_jobs(&errs);
376390
return e;
377391
}
378-
379-
errs.pop_front();
380392
}
381393

382394

@@ -402,11 +414,11 @@ Result<std::shared_ptr<HeifPixelImage>> ImageItem_Grid::decode_full_grid_image(c
402414

403415
while (!errs.empty()) {
404416
Error e = errs.front().get();
417+
errs.pop_front();
405418
if (e) {
419+
wait_for_jobs(&errs);
406420
return e;
407421
}
408-
409-
errs.pop_front();
410422
}
411423
}
412424
#endif

0 commit comments

Comments
 (0)