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

未关闭 适合新手
#65 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
79/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp, python

调研方向

从报告所指的第240行附近开始检查 python/decoder.cpp,查看 NVIMGCODEC_MAX_IMAGE_SIZE 是如何解析的。然后阅读 test/python/test_cpu_only.py,了解现有的解码器测试模式,并在一个新的解释器中使用 issue 中的 16×16 PPM 示例复现问题。配置的字节限制得到遵守且回归测试通过,即为完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Jupyter Notebook
星标
164
派生
26
平均合并
27 分钟
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NVIDIA/nvImageCodec 的其他 Issue

查看 NVIDIA/nvImageCodec 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。