Skip to content

TCK streamlines gets stuck when file is not a TCK #1139

Closed
@anibalsolon

Description

@anibalsolon

Currently, the nibabel.streamlines.tck.TckFile (haven't looked at the other formats) does not verify that a file is a .tck (i.e. has the "magic number" mrtrix tracks).

Since it does not verifies it, the code goes straight to try to read the key-value headers and get stuck in a loop, waiting for an "END". readline does not check for EOF.

If _read_header was a class method, it would be possible to do:

if magic_number.strip() != cls.MAGIC_NUMBER:
    msg = ("TCK magic number not found.")
    raise HeaderError(msg)

however, being a static method, one could only reference the TckFile.MAGIC_NUMBER (or any other way really).
Also, a better way to read the lines would be better, and detect EOF.

This is my new while true (and a test case for this issue):

echo "hello\nthere" > test.tck; python -c "import nibabel as nb; nb.streamlines.load('test.tck')"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions