Skip to content

Add parameter to the decode functions - #9399

Merged
kevinbackhouse merged 4 commits into
Exiv2:mainfrom
kevinbackhouse:max-recursion-plumbing
Aug 17, 2026
Merged

Add parameter to the decode functions#9399
kevinbackhouse merged 4 commits into
Exiv2:mainfrom
kevinbackhouse:max-recursion-plumbing

Conversation

@kevinbackhouse

@kevinbackhouse kevinbackhouse commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

This PR is the next step after #9396. It's plumbing to get the max_recursion_depth parameter to all the places that it needs to go.

I wasn't expecting to have to change this many files. Most of the changes are because I wanted to remove this hard-coded limit:

static const size_t max_recursion_limit_ = 1000;

In order to get the new parameter there, I needed to add a new parameter to all the "decode" functions, which are mostly static class methods.

Similar to #9396, I have tried to future-proof this change by adding a new class named DecodeParams.

@kevinbackhouse
kevinbackhouse force-pushed the max-recursion-plumbing branch 2 times, most recently from 6a9161a to 3e6063a Compare July 30, 2026 21:38
@kevinbackhouse
kevinbackhouse force-pushed the max-recursion-plumbing branch from 3e6063a to e9636c5 Compare July 31, 2026 19:07
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.26087% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.61%. Comparing base (feb9468) to head (53ad1a1).
⚠️ Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
src/cr2image.cpp 0.00% 4 Missing ⚠️
src/bmffimage.cpp 62.50% 2 Missing and 1 partial ⚠️
src/mrwimage.cpp 0.00% 2 Missing ⚠️
src/pngchunk_int.cpp 60.00% 0 Missing and 2 partials ⚠️
src/xmp.cpp 75.00% 0 Missing and 2 partials ⚠️
src/epsimage.cpp 50.00% 0 Missing and 1 partial ⚠️
src/image.cpp 85.71% 0 Missing and 1 partial ⚠️
src/jp2image.cpp 80.00% 0 Missing and 1 partial ⚠️
src/jpgimage.cpp 75.00% 0 Missing and 1 partial ⚠️
src/psdimage.cpp 75.00% 0 Missing and 1 partial ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9399      +/-   ##
==========================================
+ Coverage   65.48%   65.61%   +0.13%     
==========================================
  Files         116      117       +1     
  Lines       21534    21596      +62     
  Branches    10712    10740      +28     
==========================================
+ Hits        14102    14171      +69     
+ Misses       5141     5133       -8     
- Partials     2291     2292       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR plumbs a new DecodeParams parameter through the various static decode() entry points so max_recursion_depth can be configured consistently across formats, removing the previously hard-coded recursion limit in XMP XML validation.

Changes:

  • Introduced DecodeParams and added it as a parameter to multiple decode() APIs (Exif/TIFF/XMP/PNG chunks, etc.).
  • Stored max_recursion_depth on Image (and removed per-derived copies) so image readers can propagate it to decode paths.
  • Updated unit tests and sample programs to supply DecodeParams explicitly.
Show a summary per file
File Description
unitTests/unittest_utils.hpp Adds a shared recursion depth constant and declares default DecodeParams helper.
unitTests/unittest_utils.cpp Uses the shared constant and implements defaultDecodeParams().
unitTests/test_xmp_race_encode_decode.cpp Passes DecodeParams to XmpParser::decode() in concurrency tests.
unitTests/test_xmp_ns_leak.cpp Passes DecodeParams to XmpParser::decode() in namespace regression tests.
unitTests/test_xmp_concurrent_registry.cpp Passes DecodeParams to XmpParser::decode() in registry concurrency test.
src/xmpsidecar.cpp Propagates max_recursion_depth_ into XMP decode via DecodeParams.
src/xmp.cpp Removes hard-coded recursion limit; enforces recursion depth via DecodeParams in XML validation; updates XMP decode signature.
src/webpimage.cpp Passes DecodeParams into Exif/XMP decoding from WebP chunks.
src/tiffvisitor_int.hpp Extends TiffDecoder ctor to accept DecodeParams and stores max recursion depth.
src/tiffvisitor_int.cpp Threads DecodeParams into TiffDecoder and XMP decode within TIFF.
src/tiffimage_int.hpp Extends TiffParserWorker::decode() to accept DecodeParams.
src/tiffimage_int.cpp Passes DecodeParams into TiffDecoder construction.
src/tiffimage.cpp Threads DecodeParams through TiffParser::decode() and image readers.
src/tifffwd_int.hpp Forward declares DecodeParams for internal TIFF code.
src/rw2image.cpp Threads DecodeParams through RW2 decode into TIFF worker.
src/rafimage.cpp Passes DecodeParams to embedded TIFF parsing.
src/quicktimevideo.cpp Removes per-class recursion depth storage (now relies on base Image).
src/psdimage.cpp Passes DecodeParams into PSD Exif and XMP decode paths.
src/pngimage.cpp Creates DecodeParams and passes it into PNG text/exif chunk decoders.
src/pngchunk_int.hpp Updates PNG chunk decode/parse APIs to accept DecodeParams.
src/pngchunk_int.cpp Threads DecodeParams into TIFF/XMP decode from PNG chunk content.
src/orfimage.cpp Threads DecodeParams through ORF decode into TIFF worker.
src/mrwimage.cpp Passes DecodeParams to TIFF parser for MRW.
src/jpgimage.cpp Passes DecodeParams into JPEG Exif and XMP decode paths.
src/jp2image.cpp Passes DecodeParams into JP2 embedded Exif and XMP decode paths.
src/image.cpp Stores max_recursion_depth_ on Image and uses it for setXmpPacket() decode.
src/exif.cpp Implements DecodeParams ctor and updates ExifParser::decode() signature to accept it.
src/epsimage.cpp Passes DecodeParams into EPS XMP decode path.
src/cr2image.cpp Threads DecodeParams into CR2 decode and TIFF worker usage.
src/bmffimage.cpp Removes per-class box depth member; uses max_recursion_depth_ and passes DecodeParams into TIFF/XMP parsing.
src/asfvideo.cpp Removes per-class recursion depth storage (now relies on base Image).
samples/xmpparser-test.cpp Updates sample to construct DecodeParams and pass to XMP decode.
samples/xmpparse.cpp Updates sample to construct DecodeParams and pass to XMP decode.
samples/tiff-test.cpp Updates sample to pass DecodeParams into Exif decode.
include/exiv2/xmp_exiv2.hpp Updates XmpParser::decode() API to accept DecodeParams (forward declared).
include/exiv2/tiffimage.hpp Updates TiffParser::decode() API to accept DecodeParams.
include/exiv2/rw2image.hpp Updates Rw2Parser::decode() API to accept DecodeParams.
include/exiv2/quicktimevideo.hpp Removes derived-class recursion depth member (base Image now stores it).
include/exiv2/orfimage.hpp Updates OrfParser::decode() API to accept DecodeParams.
include/exiv2/image.hpp Adds max_recursion_depth_ member to Image.
include/exiv2/exif.hpp Introduces DecodeParams and updates ExifParser::decode() API signature.
include/exiv2/cr2image.hpp Updates Cr2Parser::decode() API to accept DecodeParams.
include/exiv2/bmffimage.hpp Removes derived-class max box depth member (base Image now used).
include/exiv2/asfvideo.hpp Removes derived-class recursion depth member (base Image now stores it).

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Suppressed comments (3)

unitTests/unittest_utils.hpp:1

  • Exiv2::DecodeParams is referenced here but this header only includes <exiv2/image.hpp>, which (based on the changes shown) does not declare DecodeParams. This is likely to fail compilation for any TU including unittest_utils.hpp. Fix by including <exiv2/exif.hpp> here, or by adding a forward declaration namespace Exiv2 { class DecodeParams; } before the function declaration (note: forward declaration is sufficient for a return-by-value declaration, but the definition must still include the full header).
    src/xmp.cpp:1
  • The recursion limit behavior for XMP decoding is now parameterized via DecodeParams (previously hard-coded). It would be good to add a focused unit test that sets a very small max_recursion_depth and asserts XmpParser::decode() fails on a deliberately deep-but-well-formed XML packet, and succeeds with a larger depth. This would catch regressions where dp is accidentally ignored in the future.
    src/xmp.cpp:1
  • The recursion limit behavior for XMP decoding is now parameterized via DecodeParams (previously hard-coded). It would be good to add a focused unit test that sets a very small max_recursion_depth and asserts XmpParser::decode() fails on a deliberately deep-but-well-formed XML packet, and succeeds with a larger depth. This would catch regressions where dp is accidentally ignored in the future.
  • Files reviewed: 44/44 changed files
  • Comments generated: 4
  • Review effort level: Lite

Comment thread include/exiv2/image.hpp
Comment thread include/exiv2/exif.hpp Outdated
Comment thread src/pngimage.cpp Outdated
Comment thread src/image.cpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

Suppressed comments (2)

include/exiv2/params.hpp:8

  • params.hpp uses size_t but does not include a standard header that defines it. Relying on transitive includes makes this public header non-self-contained and can break downstream builds depending on include order.
// *****************************************************************************
#include "exiv2lib_export.h"

include/exiv2/params.hpp:18

  • The doc comment says "Similar to ImageCtorParams above" but ImageCtorParams is not declared in this header. This makes the documentation confusing for readers of params.hpp in isolation.
  @brief Parameters for the "decode" functions. There are a fairly large
  number of static "decode" functions. Examples are `ExifParser::decode`,
  `TiffParser::decode`, and `XmpParser::decode`. Similar to `ImageCtorParams` above,
  this class is a common set of parameters for those functions. It currently
  only contains a `max_recursion_depth_` field, but it will make it easier to
  • Files reviewed: 45/45 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@kevinbackhouse
kevinbackhouse marked this pull request as ready for review August 1, 2026 23:53
@kevinbackhouse
kevinbackhouse requested review from kmilos and neheb August 1, 2026 23:53
@mergify

mergify Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@kevinbackhouse
kevinbackhouse merged commit 70c15f1 into Exiv2:main Aug 17, 2026
105 of 106 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants