-
Notifications
You must be signed in to change notification settings - Fork 31
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
read_bytes(): add extra length check #61
Comments
kaitai-io/kaitai_struct_cpp_stl_runtime#46 does just that, only in C++, not Python. |
I read some of the comments and the one about infinite streams makes sense. For me personally this is not relevant at all, but I guess it might be relevant for others. Would it perhaps be possible to add a variant and making it conditional upon for example an environment variable, with the current implementation being the default? |
I think we're actually looking for
|
I've implemented this in 349a861, but I wonder if this won't slow down the overall parsing significantly - the Even just calling def seekable(self):
"""Return a bool indicating whether object supports random access.
If False, seek(), tell() and truncate() will raise OSError.
This method may need to do a test seek().
"""
return False But this potential issue just randomly occurred to me, it's not confirmed, any chance you can do a benchmark? If it's really an issue, I think we can introduce a threshold on the number of bytes requested where it's actually cheaper to call |
I still need to dig into this deeper but one call to
This can be easily verified:
which is the correct size of the binary:
So this:
can be turned into:
|
@armijnhemel I applied your suggestion, thanks for looking into this. |
read_bytes()
could benefit from an extra length check. I am using kaitai struct for parsing and there are plenty of false positives for certain file types. I sometimes end up reading a lot of extra data. With an extra check to see if the amount of bytes to be read is smaller than the stream size or file size this would be avoided:for example could be rewritten to something like:
or something similar.
Right now I am trying to work around this by adding extra boundary checks in the
.ksy
files that looks at the size of the file, but that's a rather ugly hack.The text was updated successfully, but these errors were encountered: