Skip to content

Serialize buffered binary element values to JSON - #2409

Open
galafis wants to merge 1 commit into
pydicom:mainfrom
galafis:fix-buffered-json-values
Open

galafis wants to merge 1 commit into
pydicom:mainfrom
galafis:fix-buffered-json-values

Conversation

@galafis

@galafis galafis commented Oct 24, 2026

Copy link
Copy Markdown

Binary element values may be readable, seekable buffers, but Dataset.to_json() passes them directly to base64 encoding and the bulk-data path calls len() on them. Both paths raise TypeError for supported buffered Pixel Data values.

Measure buffered values with buffer_length. If a BulkDataURI handler is selected, pass the original element to it without reading the value. Otherwise, encode the full buffer as InlineBinary and restore its original position. Regressions cover OB/OW inline round trips and a bulk-data buffer whose read method raises, proving that URI serialization does not materialize the data.

Validation: all 3 regressions fail on main before the fix. JSON, data-element, file-writer and file-utility suites pass afterwards (640 passed, 5 skipped, 3 warnings from existing validation tests). Repository-pinned Ruff 0.15.12 lint/format checks and git diff --check pass. Mypy 1.20.2 with Python 3.12 reports six errors in unchanged pixels/utils.py during followed imports; no full type-check pass is claimed. A changed-file check with followed-import diagnostics suppressed is recorded in validation. Python 3.12.14, NumPy 2.5.4, pydicom 3.1.0.dev0. Full package tests and documentation build were not run. A release note is included.

This branch has not been deployed

No deployments
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.

1 participant