-
Notifications
You must be signed in to change notification settings - Fork 261
FIX: Handles invalid TCK files, prevents infinite loop #1140
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
Conversation
Codecov ReportBase: 91.80% // Head: 91.81% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #1140 +/- ##
==========================================
+ Coverage 91.80% 91.81% +0.01%
==========================================
Files 101 101
Lines 12453 12469 +16
Branches 2432 2239 -193
==========================================
+ Hits 11433 11449 +16
Misses 693 693
Partials 327 327
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Thanks @anibalsolon! This looks perfectly sensible. Two thoughts:
The first would be good to address here. The second can wait for another PR unless you're feeling really eager to explore this. |
Looks good. Thanks! |
@effigies Hey! Sorry, I started answering here and got distracted. Thank you for the review, good one about the For 2, the TCK file should be in binary mode, given that the data will be binary. I am working on a fix for that. Regarding this text/binary mode guarantee, when providing a file object for Opener, would it be beneficial to make sure the file object is in the same mode as the requested for Opener? e.g.
Given the file object is provided directly to the Opener in some interfaces/formats (TCK and TRK), we do not know what the mode the fd is in. Or would it be better to do the checking in another layer of the code? I usually prefer to do these checkings instead of letting a random exception explode in the user's face, but not sure what's the philosophy for nibabel. |
Ah, sorry for jumping the gun. I agree it would make sense for the opener to raise an exception for a mode mismatch, but I'm not sure if we should start enforcing it when there is no explicit mode. In any event, this would be an API change. So in the short term: fname = 'file'
fd = open('file', 'r')
assert Opener(fname).mode == 'rb'
assert Opener(fname, mode='r').mode == 'r'
assert Opener(fd).mode == 'r'
assert Opener(fd, mode='r').mode == 'r'
with assert_raises(IOError):
Opener(fd, 'rb')
with assert_raises(IOError):
Opener(fd, 'w') If we do want to make |
Proper check for the magic number and the header's end, stopping the search at EOF.
Resolves #1139