8000 opencv: use the registry's zlib, libpng, libjpeg-turbo, libwebp; OpenEXR and IPP off by bryan-minimal · Pull Request #1575 · gominimal/pkgs · GitHub
[go: up one dir, main page]

Skip to content

opencv: use the registry's zlib, libpng, libjpeg-turbo, libwebp; OpenEXR and IPP off - #1575

Merged
bryan-minimal merged 1 commit into
mainfrom
opencv-system-codecs
Nov 19, 2026
Merged

bryan-minimal merged 1 commit into
mainfrom
opencv-system-codecs

Conversation

@bryan-minimal
Copy link
Copy Markdown
Member

Problem

opencv compiles its own 3rdparty/ copies of the image libraries and links them statically into libopencv_imgcodecs. It does that whenever find_package fails (cmake/OpenCVFindLibsGrfmt.cmake at 4.14.0), and it failed for all of them here because none was a build dep. BUILD_PNG and the rest were already OFF on Linux; they do not stop the fallback.

The copies are invisible to pkgscan, and two are older than the registry's packages:

library bundled in opencv 4.14.0 registry
libpng 1.6.57 1.6.59
libjpeg-turbo 3.1.2 3.2.1
libwebp ABI 0x0210 1.6.0
zlib bundled copy (zlib was not a build dep) 1.4
libtiff 4.7.1 not packaged
OpenEXR 2.3.0 (2018) not packaged

The recipe already did this for openjpeg (OSV-2023-444).

Change

  • Unbundled: zlib, libpng, libjpeg-turbo, libwebp (and openjpeg, as before). They are build deps, and libpng, libjpeg-turbo and libwebp are new runtime deps (zlib and openjpeg already were). Plain deps, not subsetOf, as every other recipe that depends on these three does.
  • WITH_OPENEXR=OFF: no OpenEXR package, and the bundled 2.3.0 carries a long OSS-Fuzz CVE tail. EXR decoding was already opt-in at runtime (OPENCV_IO_ENABLE_OPENEXR), so default behaviour does not change.
  • WITH_IPP=OFF: on x86_64 opencv downloads Intel's prebuilt IPPICV archive at configure time (3rdparty/ippicv/ippicv.cmake, md5-pinned only) and links it statically into libopencv_core. That is a binary we did not build, under Intel's licence rather than the package's Apache-2.0, fetched outside the recipe's sha256-pinned sources. I turned it off rather than deferring it because it costs one flag. The x86 imgproc kernels IPP accelerated fall back to opencv's own SIMD code, which is slower for some operations. arm64 never had IPP.
  • Fail-closed checks in build.sh (in the style of llama.cpp's):
    • After make: no 3rdparty/lib/{libzlib,liblibpng,liblibjpeg-turbo,liblibwebp,liblibopenjp2,libIlmImf}.a. The check also requires the bundled liblibtiff.a to be there, so a moved directory cannot make it pass vacuously.
    • After install: readelf -d libopencv_imgcodecs.so.* must list libz, libpng16, libjpeg, libwebp and libopenjp2 as NEEDED.
  • New standalone test image_codecs: compiles a small C++ program against the installed headers. It writes a PNG, a JPEG and a WebP, reads each one back, and checks the result: PNG must be exact, JPEG and WebP within tolerance. The package ships no cv2, so the test uses a C++ program, following the pattern of jsoncpp's and c-ares's tests.

Recipe evaluated locally with the patched stdlib (pkgs-nickel-eval) for amd64 and arm64. Not built anywhere yet; the build-bot run on this PR is the first build.

Not in this PR (follow-ups)

  • protobuf (dnn) is still the bundled 3.19.1. opencv's pregenerated .pb.cc files are for 3.19, and ours is 36.2 (PROTOBUF_UPDATE_FILES=ON, abseil linkage), so it needs its own PR.
  • libtiff is still the bundled 4.7.1, because the registry has no libtiff package. Packaging it would also help ghostscript, which passes --with-system-libtiff. The build.sh check expects the bundled copy, so switching to a package has to update the check.
  • Other configure-time downloads remain: KleidiCV source on arm64 (hal/kleidicv/kleidicv.cmake, gitlab.arm.com) and ADE for G-API (modules/gapi/cmake/DownloadADE.cmake) on both arches. Both are source archives pinned by md5 only. They should be mirrored and sha256-pinned like the or-tools Eigen source (pkgs#1146).
  • ittnotify, quirc and flatbuffers are still the vendored copies; the registry has no packages for them.

🤖 Generated with Claude Code

…nstead of bundled copies

opencv compiled its 3rdparty/ copies of these into libopencv_imgcodecs
because none of them was a build dep, so find_package failed and opencv
fell back to the bundled sources. The bundled libpng (1.6.57) and
libjpeg-turbo (3.1.2) are older than our packages and invisible to pkgscan.

- Build + runtime deps: libpng, libjpeg-turbo, libwebp; zlib as a build dep.
- WITH_OPENEXR=OFF: no OpenEXR package; the bundled 2.3.0 is from 2018.
- WITH_IPP=OFF: stops the configure-time download of Intel's prebuilt
  IPPICV binary on x86_64.
- build.sh fails closed if a bundled copy was built, or if
  libopencv_imgcodecs lacks DT_NEEDED on libz, libpng16, libjpeg, libwebp
  or libopenjp2.
- New standalone test: PNG/JPEG/WebP round trip through imgcodecs.

libtiff stays bundled (no package); protobuf is a follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner November 18, 2026 20:38
@coderabbitai
coderabbitai Bot commented Nov 18, 2026
Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 2 billable files and costs up to $0.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 56 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 63 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9cebbef and 82958d3.

Files selected for processing: 2

  • packages/opencv/build.ncl
  • packages/opencv/build.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@norrietaylor norrietaylor left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Scope matches the title. Both files change only the opencv recipe, and no other recipe imports packages/opencv/build.ncl, so the new runtime deps reach no dependent.

Clobber none. The diff keeps the openjpeg unbundling from #301 and its OSV-2023-444 rationale, and it keeps the smoketest from #1364.

Correctness The recipe is sound on read. The registry packages ship the headers and the shared libraries that opencv looks for, and readelf comes from binutils. The new image_codecs test follows the c-ares pattern. I found three nits only: change narration in the build.sh comment block, a WebP comment that names the wrong mode, and build deps that repeat the runtime deps.

Not checked I ran no build, and the harness denied shell commands other than git log, so gitleaks and trivy did not run. I did not open the opencv 4.14.0 source. These claims are from memory of upstream and are not verified: the 3rdparty archive names (liblibtiff.a, libzlib.a, liblibjpeg-turbo.a, libIlmImf.a), the 3rdparty/lib location, the libz DT_NEEDED on libopencv_imgcodecs under --as-needed, and the lossless default of WebP imwrite. The first build-bot run decides the first three, because the checks fail closed.

Comment thread packages/opencv/build.sh
# already the Linux default and do NOT stop the fallback: opencv builds the
# bundled copy whenever find_package fails (cmake/OpenCVFindLibsGrfmt.cmake),
# which is what happened while these libraries were not build deps. The
# checks after the build are what make this fail closed.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit · Three sentences in this block tell the history of the change, not the state of the code. They are "which is what happened while these libraries were not build deps" (line 24), "arm64 never had it" (line 43) and "a follow-up" (line 46). The first is also doubtful for zlib: zlib was a runtime dep before this PR, and runtime deps are in the build environment. Keep the mechanism (the fallback when find_package fails) and move the history to the commit message. I found this in the opencv recipe only.

Comment thread packages/opencv/build.ncl
}
double diff = cv::norm(img, back, cv::NORM_INF);
// PNG is lossless; JPEG and lossy WebP only have to be close.
if ((std::string(ext) == "png" && diff != 0) || diff > 64) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit · The comment says "lossy WebP", but cv::imwrite with no parameters writes lossless WebP. The opencv documentation for IMWRITE_WEBP_QUALITY says the default is lossless. The test can require diff == 0 for WebP as it does for PNG, which is a stronger check of the registry's libwebp. Only JPEG needs the tolerance. I did not open the 4.14.0 source to confirm the default.

Comment thread packages/opencv/build.ncl
openjpeg,
libpng,
libjpeg-turbo,
libwebp,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit · All five libraries are in runtime_deps too (lines 47-53). The repo guide says runtime deps are injected into the build environment, so an identical build_deps entry is not necessary. openjpeg was already listed twice before this PR, and this diff extends the pattern to four more. Keep one list, and put the comment about the bundled-copy fallback on the runtime_deps entries.

@bryan-minimal
bryan-minimal added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 47f0378 Nov 19, 2026
16 checks passed
@bryan-minimal
bryan-minimal deleted the opencv-system-codecs branch November 19, 2026 23:46
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.

2 participants

0