Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS" section (including "Infinity" and "NaN") #3539

Closed
N-Dekker opened this issue Aug 10, 2022 · 2 comments · Fixed by #3542
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Comments

@N-Dekker
Copy link
Contributor

N-Dekker commented Aug 10, 2022

Description

It appears that MeshFileReader hangs forever when trying to read an ASCII .vtk file that has non-numeric chars in "POINTS" section (using VTKPolyDataMeshIO). Even when the file was created by MeshFileWriter, using VTKPolyDataMeshIO as well. This may happen when some of the coordinates of the points has a NaN or an infinite value.

Note than MeshFileReader does correctly process reading NaN and infinite values from a binary .vtk file. So the issue only occurs with non-binary (ASCII) .vtk files.

Steps to Reproduce

#include "itkMesh.h"
#include "itkMeshFilereader.h"
#include "itkMeshFileWriter.h"

int
main()
{
  using MeshType = itk::Mesh<int>;
  using NumericLimits = std::numeric_limits<float>;
  const auto inputMesh = MeshType::New();
  inputMesh->SetPoint(0, itk::MakePoint(42.0f, NumericLimits::infinity(), NumericLimits::quiet_NaN()));
  itk::WriteMesh(inputMesh, "fileName.vtk");

  auto outputMesh = itk::ReadMesh<MeshType>("fileName.vtk"); // <== hangs forever...!
}

VTK file created by itk::WriteMesh(inputMesh, "fileName.vtk"):

# vtk DataFile Version 2.0
File written by itkPolyDataMeshIO
ASCII
DATASET POLYDATA
POINTS 1 float
42 Infinity NaN

Expected behavior

  • MeshFileReader should be able to read any file by created by MeshFileWriter, so it should interpret "Infinity" as the floating point value infinity, and "NaN" as Not-A-Number.
  • In other cases, when the "POINTS" section has non-numeric characters, MeshFileReader should throw an exception, rather than just hanging forever.

Actual behavior

MeshFileReader hangs inside the while loop within itk::VTKPolyDataMeshIO::ReadPointsBufferAsASCII, at

while (!inputFile.eof())

Reproducibility

100%

Versions

Latest revision at the master: 9ed9070

Additional Information

I think I'm able to fix it 😃

@N-Dekker N-Dekker added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label Aug 10, 2022
@N-Dekker N-Dekker changed the title MeshFileReader (VTKPolyDataMeshIO) hangs forever on non-numeric chars in "POINTS" section (including "Infinity", "NaN") MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS" section (including "Infinity" and "NaN") Aug 10, 2022
@jhlegarreta
Copy link
Member

jhlegarreta commented Aug 10, 2022

Not sure if I'm mixing things (sorry if that is the case), but there seem to be various issues with the mesh-related classes that might all be related to each other (at least, if issues are in the base class; or some pattern was re-used across child-specific implementations), including this one.

I did also experience the timeout issue in here:
https://github.com/InsightSoftwareConsortium/ITK/pull/3403/files#diff-4cd806c78c70c7e6a870aca2a24bced46565305bcf0562e4ca81c975e71a7c3dR142

that raised issue #3455.

and maybe your comment (?)
#3538 (comment)

and maybe Pranjal's #3526, as well as his comment in #3515 (comment)

Unfortunately, my investigations at that time did not lead me to any relevant conclusion about the source of the problem.

@N-Dekker
Copy link
Contributor Author

Thanks @jhlegarreta but this particular issue is specifically about reading, and specifically about reading the ASCII file type. So I do think the problems you're pointing at are unrelated to this particular one. Even if all of them are Mesh IO related! Thanks anyway Jon!

I'm preparing a PR now, for this particular issue. Please wait 😃

N-Dekker added a commit to N-Dekker/ITK that referenced this issue Aug 10, 2022
`MeshFileReader`/`VTKPolyDataMeshIO` did hang forever when trying to read an
ASCII .vtk file that contained non-numeric chars in "POINTS" section, for
example "Infinity" or "NaN".

With this commit, "inf" and "Infinity" will be interpreted as the floating point
value infinity, while "nan" and "NaN" will be interpreted as Not-A-Number. Other
strings of non-numeric characters in the list of point components (coordinates)
will cause the reader to throw an appropriate `itk::ExceptionObject`.

Addresses issue InsightSoftwareConsortium#3539
"MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS"
section (including "Infinity" and "NaN")"
N-Dekker added a commit to N-Dekker/ITK that referenced this issue Aug 11, 2022
`MeshFileReader`/`VTKPolyDataMeshIO` did hang forever when trying to read an
ASCII .vtk file that contained non-numeric chars in "POINTS" section, for
example "Infinity" or "NaN".

With this commit, "inf" and "Infinity" will be interpreted as the floating point
value infinity, while "nan" and "NaN" will be interpreted as Not-A-Number. Other
strings of non-numeric characters in the list of point components (coordinates)
will cause the reader to throw an appropriate `itk::ExceptionObject`.

Addresses issue InsightSoftwareConsortium#3539
"MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS"
section (including "Infinity" and "NaN")"
hjmjohnson pushed a commit that referenced this issue Aug 12, 2022
`MeshFileReader`/`VTKPolyDataMeshIO` did hang forever when trying to read an
ASCII .vtk file that contained non-numeric chars in "POINTS" section, for
example "Infinity" or "NaN".

With this commit, "inf" and "Infinity" will be interpreted as the floating point
value infinity, while "nan" and "NaN" will be interpreted as Not-A-Number. Other
strings of non-numeric characters in the list of point components (coordinates)
will cause the reader to throw an appropriate `itk::ExceptionObject`.

Addresses issue #3539
"MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS"
section (including "Infinity" and "NaN")"
hjmjohnson pushed a commit to BRAINSia/ITK that referenced this issue Aug 17, 2022
`MeshFileReader`/`VTKPolyDataMeshIO` did hang forever when trying to read an
ASCII .vtk file that contained non-numeric chars in "POINTS" section, for
example "Infinity" or "NaN".

With this commit, "inf" and "Infinity" will be interpreted as the floating point
value infinity, while "nan" and "NaN" will be interpreted as Not-A-Number. Other
strings of non-numeric characters in the list of point components (coordinates)
will cause the reader to throw an appropriate `itk::ExceptionObject`.

Addresses issue InsightSoftwareConsortium#3539
"MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS"
section (including "Infinity" and "NaN")"
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this issue Aug 26, 2022
`MeshFileReader`/`VTKPolyDataMeshIO` did hang forever when trying to read an
ASCII .vtk file that contained non-numeric chars in "POINTS" section, for
example "Infinity" or "NaN".

With this commit, "inf" and "Infinity" will be interpreted as the floating point
value infinity, while "nan" and "NaN" will be interpreted as Not-A-Number. Other
strings of non-numeric characters in the list of point components (coordinates)
will cause the reader to throw an appropriate `itk::ExceptionObject`.

Addresses issue InsightSoftwareConsortium#3539
"MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS"
section (including "Infinity" and "NaN")"
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this issue Aug 26, 2022
`MeshFileReader`/`VTKPolyDataMeshIO` did hang forever when trying to read an
ASCII .vtk file that contained non-numeric chars in "POINTS" section, for
example "Infinity" or "NaN".

With this commit, "inf" and "Infinity" will be interpreted as the floating point
value infinity, while "nan" and "NaN" will be interpreted as Not-A-Number. Other
strings of non-numeric characters in the list of point components (coordinates)
will cause the reader to throw an appropriate `itk::ExceptionObject`.

Addresses issue InsightSoftwareConsortium#3539
"MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS"
section (including "Infinity" and "NaN")"
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this issue Aug 26, 2022
`MeshFileReader`/`VTKPolyDataMeshIO` did hang forever when trying to read an
ASCII .vtk file that contained non-numeric chars in "POINTS" section, for
example "Infinity" or "NaN".

With this commit, "inf" and "Infinity" will be interpreted as the floating point
value infinity, while "nan" and "NaN" will be interpreted as Not-A-Number. Other
strings of non-numeric characters in the list of point components (coordinates)
will cause the reader to throw an appropriate `itk::ExceptionObject`.

Addresses issue InsightSoftwareConsortium#3539
"MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS"
section (including "Infinity" and "NaN")"
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this issue Aug 26, 2022
`MeshFileReader`/`VTKPolyDataMeshIO` did hang forever when trying to read an
ASCII .vtk file that contained non-numeric chars in "POINTS" section, for
example "Infinity" or "NaN".

With this commit, "inf" and "Infinity" will be interpreted as the floating point
value infinity, while "nan" and "NaN" will be interpreted as Not-A-Number. Other
strings of non-numeric characters in the list of point components (coordinates)
will cause the reader to throw an appropriate `itk::ExceptionObject`.

Addresses issue InsightSoftwareConsortium#3539
"MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS"
section (including "Infinity" and "NaN")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants