Fix escaped string parsing in numpy headers#6380
Conversation
|
| Filename | Overview |
|---|---|
| dali/util/numpy.cc | Fixes out-of-bounds read in ParseStringValue by checking for null terminator after incrementing past a backslash escape before entering the switch; logic and all existing escape sequences are preserved. |
| dali/util/numpy_test.cc | Adds a regression test for the trailing-escape bug and updates the copyright year; the new entry is correctly comma-separated in the error-case vector. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["for loop: *input != '\\0'"] --> B{"*input == '\\\\'?"}
B -- No --> C{"*input == delim_end?"}
C -- Yes --> D[break]
C -- No --> E["out += *input"]
E --> A
B -- Yes --> F["input++ (advance past backslash)"]
F --> G{"*input == '\\0'?"}
G -- Yes --> H["DALI_ENFORCE fails\n(new guard — trailing escape rejected)"]
G -- No --> I["switch(*input)\n(process escape sequence)"]
I --> A
D --> J["DALI_ENFORCE *input == delim_end"]
J --> K[return out]
Reviews (3): Last reviewed commit: "Fix escaped string parsing in numpy head..." | Re-trigger Greptile
Reject a trailing escape in numpy header string values before the parser advances past the null terminator. This prevents malformed .npy headers from triggering an out-of-bounds read during header parsing. Add a focused parser regression for a descr field ending with an escape character. Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
177e4a5 to
8cd7b9b
Compare
|
!build |
|
CI MESSAGE: [53264998]: BUILD STARTED |
|
CI MESSAGE: [53264998]: BUILD PASSED |
Category:
Bug fix (non-breaking change which fixes an issue)
Description:
Fixes malformed
.npyheader parsing when a string value ends with anunfinished backslash escape.
ParseStringValueadvanced to the string terminator while handling theescape and then allowed the loop increment to move past the terminator. The
parser now rejects a trailing escape before continuing, so malformed headers
fail cleanly instead of reading past the header buffer.
Additional information:
Affected modules and functionalities:
dali/util/numpy.cc: reject an unfinished escape sequence in numpy headerstring values.
dali/util/numpy_test.cc: add parser coverage for adescrfield endingwith a backslash escape.
Key points relevant for the review:
Please check that the pointer advancement in
ParseStringValuestillpreserves the existing behavior for supported escape sequences while rejecting
the unterminated escape case before the loop increment runs.
Tests:
Ran:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A