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

Filesize detection doesn't work for compressed files #50

Merged
merged 4 commits into from
Oct 21, 2019
Merged

Conversation

tstenner
Copy link
Contributor

https://github.com/xdf-modules/xdf-python/blob/a6c5f84860c41de9d63fc3f66ac7cac0f7779bc7/pyxdf/pyxdf.py#L235-L245

For compressed files, reading the file is aborted as soon as an invalid chunk size is read and the position in the uncompressed stream is after the compressed size. So, the new code checks if more than 1024 bytes are actually readable.

Copy link
Contributor

@cbrnr cbrnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but what's the special meaning of 1024 bytes here? Where does this number come from? A comment in the code would be helpful.

@tstenner
Copy link
Contributor Author

I have no idea where the 1024 bytes came from. I suspect that it wasn't considered too useful to find a boundary chunk if the file is too close to the end, but how the 1024 came from that I don't know.

@cbrnr
Copy link
Contributor

cbrnr commented Oct 21, 2019

Can you add this explanation as a comment (it makes sense to not look for boundary chunks very close to the end of a file)?

@tstenner
Copy link
Contributor Author

It doesn't matter how much data is left, so I changed the check to read only one byte. If there's not enough left for a boundary chunk, _scan_forward will read until the end of the file and then quit. It's a tiny bit slower, but we've gotten rid of one magic number.

@cbrnr
Copy link
Contributor

cbrnr commented Oct 21, 2019

And this happens only for corrupt files anyway, right?

@tstenner
Copy link
Contributor Author

Yes with a tiny bit of fineprint. For regular files it shouldn't happen.

pyxdf/pyxdf.py Outdated
f.seek(-1, 1)
if _scan_forward(f):
continue
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you could get rid of this else: break block because you have the same thing right in the next else block. I.e. I think you can remove the first else block completely (the one belonging to the if _scan_forward(f)), and also remove the second else and dedent the two subsequent lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I've changed it.

@cbrnr cbrnr merged commit ad98e89 into master Oct 21, 2019
@cbrnr
Copy link
Contributor

cbrnr commented Oct 21, 2019

Thanks @tstenner!

@cbrnr cbrnr deleted the robustness branch October 21, 2019 14:05
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.

2 participants