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

Đang mở Phù hợp với người mới
#65 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
79/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp, python
Lĩnh vực
backend, computer-vision

Hướng nghiên cứu

Bắt đầu trong python/decoder.cpp gần dòng 240 được báo cáo và kiểm tra cách NVIMGCODEC_MAX_IMAGE_SIZE được phân tích. Sau đó, đọc test/python/test_cpu_only.py để xem các mẫu kiểm thử decoder hiện có và tái hiện lỗi bằng ví dụ PPM 16×16 trong issue trên một trình thông dịch mới. Hoàn thành khi giới hạn byte được cấu hình được tuân thủ và kiểm thử hồi quy chạy thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Jupyter Notebook
Star
164
Fork
26
Merge trung bình
27 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NVIDIA/nvImageCodec

Tất cả issue của NVIDIA/nvImageCodec

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.