Repository navigation
BUG: Check stream state after each ASCII component read - #6609
Merged
hjmjohnson merged 1 commit intoJul 13, 2026
Merged
hjmjohnson merged 1 commit into
hjmjohnson merged 1 commit into
Conversation
ReadBuffer kept one temp outside the loop and never checked the stream after extraction, so an overflowing or malformed field left failbit set and silently replayed the same stale value into every remaining buffer slot instead of failing. Addresses item B61 of InsightSoftwareConsortium#6575.
Contributor
|
| Filename | Overview |
|---|---|
| Modules/IO/ImageBase/src/itkImageIOBase.cxx | Checks stream failure after each ASCII component extraction before writing to the destination buffer. |
| Modules/IO/ImageBase/test/itkImageIOBaseGTest.cxx | Adds a small concrete test subclass and an overflow regression test for ReadBufferAsASCII. |
Reviews (1): Last reviewed commit: "BUG: Check stream state after each ASCII..." | Re-trigger Greptile
This was referenced Jul 13, 2026
dzenanz
approved these changes
Jul 13, 2026
hjmjohnson
approved these changes
Jul 13, 2026
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.
ImageIOBase::ReadBufferAsASCII()never checks the stream after an extraction, so one bad field latches its value into every remaining component. Reading5 99999 7 8asshortyields[5, 32767, 32767, 32767]. Addresses B61 of #6575.Root cause
The
ReadBuffertemplate inModules/IO/ImageBase/src/itkImageIOBase.cxxdeclares its extraction variable once, outside the loop, and never inspects the stream:C++11 changed
operator>>on overflow to clamp the value and setfailbit. So99999into ashortwrites32767and latchesfailbit; from then on everyis >> tempis a no-op,tempkeeps its stale saturated value, and that value is written into every remaining slot. The real data after the bad field is dropped with no error at all.tempis now declared inside the loop with{}zero-init — removing its cross-iteration dual meaning of "freshly read value" versus "stale leftover" — and the stream is checked after each extraction, throwing immediately on failure.Anchor
rg 'is >> temp'inModules/IO/ImageBase/src/: exactly one hit, fixed. The same shape exists inVTKImageIO::ReadTensorBuffer— that is a different module and is fixed on the VTK branch for this issue rather than folded in here.Local validation
Test added to the existing
itkImageIOBaseGTest.cxx.ImageIOBase.ReadBufferAsASCIIThrowsOnOverflowingField— synthesizes"5 99999 7 8"read as fourshorts. Fail-before:EXPECT_THROWfailed, "it throws nothing" (the buffer silently came back as[5, 32767, 32767, 32767]). Pass-after: OK.ctest -R "ImageIOBase|ConvertBuffer|IOCommon|VTKImageIO|VTIImageIO": all pass. The failures in this local run (itkImageFileReaderStreamingTest*,itkImageFileReaderDimensionsTest_NRRD, …) are missing ExternalData fixtures in the local cache and throw at file lookup, before any ASCII buffer read.AI assistance