Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: reject short fileobj reads - #2887

Draft
dfgvaetyj3456356-hash wants to merge 1 commit into
h5py:masterfrom
dfgvaetyj3456356-hash:security/fileobj-short-read
Draft

fix: reject short fileobj reads#2887
dfgvaetyj3456356-hash wants to merge 1 commit into
h5py:masterfrom
dfgvaetyj3456356-hash:security/fileobj-short-read

Conversation

@dfgvaetyj3456356-hash

Copy link
Copy Markdown

Summary

Fixes #2835.

The fileobj VFD read callback now treats short reads as failures for both file-like read paths:

  • checks the byte count returned by readinto() before returning success
  • returns -1 for short read() results, matching herr_t failure conventions

Previously, readinto() results were ignored, so a file-like object that returned fewer bytes than requested could leave part of the destination buffer untouched while the callback still returned success. The fallback read() path also returned 1 for a short read, which is non-negative and therefore not a conventional herr_t failure.

Tests

Added TestFileObj.test_short_readinto, which builds a valid in-memory HDF5 file and then serves it through a file-like object whose readinto() intentionally returns one byte short.

Local checks run:

  • python -m py_compile h5py\tests\test_file2.py
  • git diff --check

I could not run the new runtime test locally in this checkout because Cython is not installed here, and this change touches a Cython template that needs the normal h5py extension build.

@tacaswell
tacaswell marked this pull request as draft June 4, 2026 03:00
@tacaswell
tacaswell marked this pull request as draft June 4, 2026 03:00
@tacaswell

Copy link
Copy Markdown
Member

@dfgvaetyj3456356-hash Please test this locally.

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.39%. Comparing base (88ff342) to head (066e577).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2887   +/-   ##
=======================================
  Coverage   90.39%   90.39%           
=======================================
  Files          16       16           
  Lines        2509     2509           
=======================================
  Hits         2268     2268           
  Misses        241      241           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dfgvaetyj3456356-hash

Copy link
Copy Markdown
Author

Tested locally on Windows with an editable build of this branch against HDF5 1.12.2.\n\nEnvironment:\n- Python 3.11.9\n- h5py 3.16.0 from this checkout\n- HDF5 1.12.2 built locally with Visual Studio 2022 Build Tools\n- NumPy 2.4.6\n- Cython 3.2.5\n\nCommands/results:\n- \pytest h5py/tests/test_file2.py::TestFileObj::test_short_readinto -q\ -> \1 passed\\n- \pytest h5py/tests/test_file2.py::TestFileObj -q\ -> \9 passed, 1 skipped\\n\nAlso confirmed the PR CI/Codecov are green from the GitHub checks.

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.

readinto return value unchecked in VFD driver

2 participants