Skip to content

BUG: Report XML read errors instead of treating them as end of input - #133

Open
hjmjohnson wants to merge 2 commits into
stack/fix-image-read-complex-checkfrom
stack/pr-fix-xml-read-errors
Open

hjmjohnson wants to merge 2 commits into
stack/fix-image-read-complex-checkfrom
stack/pr-fix-xml-read-errors

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Re-submission of #42, reverted from master on 2026-09-24. Content is
unchanged from the original.

Position 11 of 11 in the deep stack. Base: stack/fix-image-read-complex-check.

Based on the pull request above it in the stack, so the diff shown here is
this change alone. Merge the stack bottom-up.

Stack order

# branch base
1 stack/test-regression-coverage master
2 stack/pr-fix-alloc-null-checks stack/test-regression-coverage
3 stack/fix-axml-skip-depth stack/pr-fix-alloc-null-checks
4 stack/pr-fix-analyzer-leaks stack/fix-axml-skip-depth
5 stack/pr-fix-sign-conversion stack/pr-fix-analyzer-leaks
6 stack/fix-fslio-64bit-arithmetic stack/pr-fix-sign-conversion
7 stack/fix-cifti-null-stream stack/fix-fslio-64bit-arithmetic
8 stack/pr-fix-calloc-transposed-args stack/fix-cifti-null-stream
9 stack/pr-fix-shorten-64-to-32 stack/pr-fix-calloc-transposed-args
10 stack/fix-image-read-complex-check stack/pr-fix-shorten-64-to-32
11 stack/pr-fix-xml-read-errors <- this PR stack/fix-image-read-complex-check

The order is the order these changes sat on master before the revert, so
it builds and tests at every step.

Commits introduced by this PR
  • BUG: Report XML read errors instead of treating them as end of input
  • ENH: Cover the XML read-error and read-success paths

Ordering for all the re-submitted work is tracked in #84.

gdevenyi and others added 2 commits September 24, 2026 07:12
axml_read_file()'s read loop:

    blen = fread(buf, 1, bsize, fp);
    ...
    done = blen < (unsigned)bsize;

A short read is the loop's only stopping condition, so an I/O failure is
indistinguishable from reaching the end of the file: the parse stops
early and the caller is handed whatever was parsed so far, with no
indication that the rest of the document was never read.  ferror() is now
checked and the failure reported.

The loop also called fread() once more after a file ending exactly on a
buffer boundary; testing feof() as part of the stopping condition removes
that read, which the clang static analyzer flags as a read at EOF.

(cherry picked from commit ea212d8)
A directory opens but cannot be read, so afni_xml_tool on cifti/testdata
reaches the ferror() branch; the test pins the diagnostic rather than
the exit status, which was already non-zero before the fix.  A second
test parses a real document and forbids that diagnostic, so a change
that reported a read error unconditionally would not pass.

(cherry picked from commit 283c5d4)
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.

3 participants