cv2 import appends a trailing ":" to LD_LIBRARY_PATH — empty entry resolves to CWD and breaks child processes
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 70/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- linux, python
- Lĩnh vực
- build-system, operating-systems
Hướng nghiên cứu
Chạy bản tái hiện tối thiểu, sau đó kiểm tra nhánh POSIX của cv2/init.py quanh các dòng 146-147 và lần theo cách BINARIES_PATHS được sử dụng. Được xem là hoàn tất khi việc import cv2 không còn tạo mục LD_LIBRARY_PATH rỗng hoặc khiến các tiến trình con không liên quan kế thừa một đường dẫn không an toàn; hãy bổ sung kiểm thử hồi quy nếu repository cung cấp vị trí kiểm thử phù hợp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Environment
- opencv-python: reproduced on 4.11.0.86, 4.12.0.88, 4.13.0.92, 4.14.0.94 and 5.0.0.93 (PyPI manylinux x86_64 wheels; earliest tested 4.11.0.86, Jan 2025)
- Python 3.13.15 / 3.14.7, Linux x86_64 (glibc; CachyOS/Arch, kernel 6.x)
Minimal reproduction
python -m venv venv && venv/bin/pip install opencv-python==5.0.0.93
venv/bin/python - <<'EOF'
import os, subprocess
print("before import:", repr(os.environ.get("LD_LIBRARY_PATH")))
import cv2
print("cv2", cv2.__version__, "after import:", repr(os.environ.get("LD_LIBRARY_PATH")))
print("child sees:", subprocess.run(["sh", "-c", "printf '%s' \"$LD_LIBRARY_PATH\""],
capture_output=True, text=True).stdout)
EOF
Observed
before import: None
cv2 5.0.0 after import: '/…/site-packages/cv2/../../lib64:'
child sees: '/…/site-packages/cv2/../../lib64:'
cv2/__init__.py (POSIX branch, cv2/__init__.py:146-147 in current wheels):
# amending of LD_LIBRARY_PATH works for sub-processes only
os.environ['LD_LIBRARY_PATH'] = ':'.join(l_vars['BINARIES_PATHS']) + ':' + os.environ.get('LD_LIBRARY_PATH', '')
Three problems in one line:
- Unconditional trailing
:— whenLD_LIBRARY_PATHwas previously unset the
variable is created with a dangling separator. Perld.so(8)semantics an empty
entry resolves to the current working directory of every child process. - Global environment mutation — the comment itself notes this "works for
sub-processes only", yet the write persists inos.environfor the whole
process lifetime, so everysubprocess/os.system/webbrowsercall made by
the host application inherits the modified path. This is invisible side-channel
state an importer cannot reasonably expect fromimport cv2. - The injected directory typically does not exist — with standard manylinux
wheel layouts the bundled libraries live inopencv_python.libs/(located via
$ORIGINRPATH), and<site-packages>/cv2/../../lib64is absent in venv,
project, and standalone-packaged layouts, so the write buys nothing while
adding the hazard.
Real-world impact
We ship a Nuitka-standalone application whose launcher cds into the release
folder. With cv2 imported, LD_LIBRARY_PATH ends with : → the release folder
(the CWD) enters the child loader path → children that load system OpenSSL
(xdg-open → kde-open, i.e. "open a URL in the default browser") resolve the
bundled, older libssl.so.3/libcrypto.so.3 instead of the system ones and die
with:
kde-open: libssl.so.3: version `OPENSSL_3.2.0' not found (required by /usr/lib/libcurl.so.4)
Any application that imports cv2 and then spawns helper processes from a
directory containing same-named libraries is affected the same way.
Suggested fix
-
Do not append a dangling separator; only write the variable when there is
something to add and prepend/append with proper joining:paths = l_vars['BINARIES_PATHS'] if paths: old = os.environ.get('LD_LIBRARY_PATH') os.environ['LD_LIBRARY_PATH'] = ':'.join(paths) + (':' + old if old else '') -
Longer term, prefer not mutating the global environment at all: the bundled
libraries are already found through$ORIGINRPATH; if an env-based fallback
is really needed, consider documenting it and cleaning up after import, or
exposing an opt-in.
Happy to send a PR to opencv-python/opencv-python (the loader __init__.py)
if you agree with the direction.
- Ngôn ngữ chính
- Python
- Star
- 5.4k
- Fork
- 1k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của opencv/opencv-python
-
[DOC] README fileCó thể làm lại được @jadhavroshani713-sys đã nhận 78 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
opencv/opencv-python#1217 · 3 bình luận ·
-
Dependency specification missing for python3.14Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
opencv/opencv-python#1165 · 2 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
opencv/opencv-python#1276 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
opencv/opencv-python#1273 · 1 bình luận ·
-
FFMPEG v8.1.1 vulnerabilitiesĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
opencv/opencv-python#1272 · 2 bình luận ·
Tất cả issue của opencv/opencv-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
huggingface/peft#3955 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
author-page correction
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
acl-org/acl-anthology#10313 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
anime duplicate exception request-theme
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
LizardByte/ThemerrDB#8926 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
huggingface/transformers#49556 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/security bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
mozilla-ai/otari#2245 ·
Maintainer thường phản hồi trong vòng 1 ngày