NVIMGCODEC_MAX_IMAGE_SIZE is parsed as a bool: any value becomes a 1 byte limit and every decode returns None

Open Beginner friendly
#65 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
79/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, python

Research direction

Start in python/decoder.cpp near the reported line 240 and inspect how NVIMGCODEC_MAX_IMAGE_SIZE is parsed. Then read test/python/test_cpu_only.py for existing decoder test patterns and reproduce with the issue's 16×16 PPM example in a fresh interpreter. Done means a configured byte limit is honored and the regression test passes.

Written by the indexing model from the issue text.

Description

Version

0.10.0 (wheel nvidia-nvimgcodec-cu12==0.10.0.9; also main at 77a7d15)

Describe the bug.

Setting NVIMGCODEC_MAX_IMAGE_SIZE to any non-zero value makes the Python Decoder return None for every image. The warning shows that the limit was read as 1:

768 > NVIMGCODEC_MAX_IMAGE_SIZE(1)

Expected: the value is used as a byte limit, so a 768 byte image decodes with NVIMGCODEC_MAX_IMAGE_SIZE=100000000. The warning text itself describes the variable as the maximum "Total image volume (height x width x channels x bytes_per_sample)".

The cause is in python/decoder.cpp (line 240 on main):

static const size_t max_image_sz = max_image_size_str && atol(max_image_size_str);

&& gives a bool, so max_image_sz is 0 or 1. The same expression is in the v0.3.0, v0.5.0 and v0.7.0 to v0.10.0 sources.

Minimum reproducible example
cat > repro.py <<'PY'
import os
from nvidia import nvimgcodec

print("nvimgcodec", nvimgcodec.__version__)
print("NVIMGCODEC_MAX_IMAGE_SIZE =", os.environ.get("NVIMGCODEC_MAX_IMAGE_SIZE"))

# A 16x16 binary PPM, 768 bytes of pixel data.
ppm = b"P6\n16 16\n255\n" + bytes(16 * 16 * 3)

decoder = nvimgcodec.Decoder(
    device_id=nvimgcodec.NVIMGCODEC_DEVICE_CPU_ONLY,
    backends=[nvimgcodec.Backend(nvimgcodec.BackendKind.CPU_ONLY)],
)
image = decoder.decode(ppm)
print("decoded:", None if image is None else image.shape)
PY
NVIMGCODEC_MAX_IMAGE_SIZE=100000000 python repro.py
Environment details
tools/print_env.sh was not run. Environment used for the repro:
x86_64 Linux, Ubuntu 24.04, Python 3.12
nvidia-nvimgcodec-cu12 0.10.0.9, CPU-only backend, no GPU visible (CUDA_VISIBLE_DEVICES empty)
Also reproduced with a from-source build of main 77a7d15 (CUDA toolkit 12.9, GCC 14.4)
Relevant log output
[WARNING] [pynvimgcodec] Total image volume (height x width x channels x bytes_per_sample) exceeds the maximum configured value: 768 > NVIMGCODEC_MAX_IMAGE_SIZE(1). Use NVIMGCODEC_MAX_IMAGE_SIZE env variable to control this maximum value.
nvimgcodec 0.10.0
NVIMGCODEC_MAX_IMAGE_SIZE = 100000000
decoded: None

Without the variable the same script prints decoded: (16, 16, 3).

Other/Misc.

A local fix is available if useful: parse the value with atoll and treat a missing, non-numeric or non-positive value as "no limit", plus a test in test/python/test_cpu_only.py that sets the variable in a fresh interpreter. The new test fails on main and passes with the change. One behaviour change: a negative value would mean "no limit" instead of "limit 1".

Check for duplicates
  • I have searched the open bugs/issues and have found no duplicates for this bug report

This was found with an AI coding assistant (Claude Code, claude-fable-5-2), which also wrote and ran the repro above and drafted this report.

Dominant language
Jupyter Notebook
Stars
164
Forks
26
Avg merge
27m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA/nvImageCodec

All issues in NVIDIA/nvImageCodec

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.