Fix validation of record_size in fortio_fread_buffer#1185
Merged
Conversation
9fdbec8 to
156fb0b
Compare
4311213 to
413e90c
Compare
There was a problem hiding this comment.
Pull request overview
This pull request updates the low-level Fortran unformatted read path to validate record sizes when reading into a fixed-size buffer, adds regression tests for malformed keyword records, and adjusts Windows wheel repair configuration.
Changes:
- Refactors
fortio_fread_buffer()to validate record sizes against the destination buffer and returnfalseon inconsistencies instead of aborting. - Adds Python tests covering malformed/unexpected record-size scenarios when reading keywords via
ResdataKW.fread(). - Adds a cibuildwheel Windows
repair-wheel-commandusingdelvewheel.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/rd_tests/test_rd_kw.py | Adds regression tests for malformed/unexpected Fortran record markers and multi-record keyword reads. |
| pyproject.toml | Configures cibuildwheel Windows wheel repair using delvewheel. |
| lib/resdata/FortIO.cpp | Refactors buffered record reading to validate record sizes and avoid overreads. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+503
to
+518
| char *end = buffer + buffer_size; | ||
| char *itr = buffer; | ||
| for (int record_size = 0; itr < end; itr += record_size) { | ||
| record_size = fortio_init_read(fortio); | ||
| if (record_size < 0) | ||
| return false; | ||
| if (end - itr < static_cast<ptrdiff_t>(record_size)) | ||
| return false; | ||
| size_t items_read = 0; | ||
| if (record_size > 0) | ||
| items_read = fread(itr, 1, record_size, fortio->stream); | ||
| if (items_read != static_cast<size_t>(record_size) || | ||
| !fortio_complete_read(fortio, record_size)) | ||
| return false; | ||
| } | ||
| return itr == end; |
Collaborator
Author
There was a problem hiding this comment.
This is not the case as encountering a zero-length record still consumes the four bytes from the stream. If the stream is not progressed, then fortio_init_read returns -1 and you get an early exit.
d74ff8a to
51ab1cd
Compare
ajaust
reviewed
Jun 10, 2026
11c7e90 to
2797737
Compare
ajaust
approved these changes
Jun 10, 2026
2797737 to
d04072c
Compare
d04072c to
1e050c9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.