Backport to 6.2#1166
Open
eivindjahren wants to merge 5 commits into
Open
Conversation
4ea055b to
b767436
Compare
b767436 to
caab03e
Compare
There was a problem hiding this comment.
Pull request overview
This PR appears to backport robustness fixes (likely from a newer branch) into the 6.2 line, focused on safer handling of GRDECL inputs and zero-length keywords, plus some CI build configuration adjustments.
Changes:
- Add Python-side handling for zero-length
ResdataKWinget_min_max()andnumpy_view(). - Harden GRDECL/grid parsing in C++ (buffer sizing, numeric parsing widths, and keyword-size/dimension validation with
util_abort). - Update
cibuildwheelconfiguration to skip*-win32builds.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/rd_tests/test_rd_kw.py | Adds a regression test asserting empty GRDECL bodies produce a zero-length keyword. |
| python/resdata/resfile/rd_kw.py | Adds safe behavior for empty keywords in get_min_max() and numpy_view(). |
| pyproject.toml | Updates cibuildwheel skip matrix to exclude win32. |
| lib/resdata/rd_kw.cpp | Adds an abort guard for typed max/min wrappers on zero-length keywords. |
| lib/resdata/rd_kw_grdecl.cpp | Adjusts GRDECL token buffer sizing and float/double scan widths. |
| lib/resdata/rd_grid.cpp | Adds GRDECL grid keyword size validation and overflow checks before allocation/usage. |
Comments suppressed due to low confidence (2)
lib/resdata/rd_kw_grdecl.cpp:232
buffer_sizewas increased to 256 and the numeric scans use%128g/%128lg, but token input is still limited byfscanf(stream, "%32s", buffer). As a result long numeric tokens are still truncated and the new buffer size/scan widths are ineffective; consider updating thefscanfwidth to match the allocated buffer (or remove the unusedbuffer_sizeindirection).
char newline = '\n';
bool atEOF = false;
size_t init_size = 32;
size_t buffer_size = 256;
size_t data_index = 0;
int sizeof_ctype = rd_type_get_sizeof_ctype(data_type);
size_t data_size = init_size;
char *buffer = (char *)util_calloc((buffer_size + 1), sizeof *buffer);
char *data = (char *)util_calloc(sizeof_ctype * data_size, sizeof *data);
while (true) {
if (fscanf(stream, "%32s", buffer) == 1) {
if (strcmp(buffer, RD_COMMENT_STRING) == 0) {
// We have read a comment marker - just read up to the end of line.
python/resdata/resfile/rd_kw.py:1094
numpy_view()now special-caseslen(self)==0to return an empty array, which changes behavior from the previous pointer-cast path. There are tests fornumpyView()on non-empty keywords but none for the empty case; please add one to ensure this stays safe and returns the expected dtype.
if len(self):
ap = ctypes.cast(self.data_ptr, ctypes.POINTER(ct * len(self)))
return np.frombuffer(ap.contents, dtype=self.dtype)
else:
return np.array([], dtype=self.dtype)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Alexander Jaust <18347253+ajaust@users.noreply.github.com>
caab03e to
db5154c
Compare
db5154c to
a472fe1
Compare
Fixing some bugs in the model test surfaced these bugs.
a472fe1 to
d45f401
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.
Backports fixes that are on main branch to version 6.2 . The only difference is that throws are now util_abort. This is to avoid changes to the error handling semantics.