You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oops, payload_position=0. We lost track of the position of the payload. That's not a very useful Tell in this case.
The reason is Tell relies stream.tell(), and several subconstructs create io.BytesIO() from data read from the original substream, which makes stream.tell() return 0. Furthermore, as far as I've been able to find, the position of the parent stream at the time of creating the BytesIO is not recorded, so this information cannot be recovered from the Container.
Fixesconstruct#1014
This patch wraps the BytesIO substreams made by the following
subconstructs during parsing:
* OffsettedEnd
* Prefixed
* FixedSize
* NullTerminated
* NullStripped
* ProcessXor
This allows the Tell construct to return offsets that are relative to
the beginning of the stream, rather than relative to the last occurence
of these subconstructs.
This has not been implemented for the following subconstructs:
* Transformed: there is no guarantee that there won't be any byte
swapping in the transformation, therefore we can't map offsets without
knowledge of the specific transformation.
* ProcessRotateLeft: tell() offsets would be decreasing, which could
cause all sorts of problems.
In both those cases, it makes more sense for the user to use a Tell
immediately before the Transformed or ProcessRotateLeft and do their own
mapping.
Fixesconstruct#1014
This patch wraps the BytesIO substreams made by the following
subconstructs during parsing:
* OffsettedEnd
* Prefixed
* FixedSize
* NullTerminated
* NullStripped
* ProcessXor
This allows the Tell construct to return offsets that are relative to
the beginning of the stream, rather than relative to the last occurence
of these subconstructs.
This has not been implemented for the following subconstructs:
* Transformed: there is no guarantee that there won't be any byte
swapping in the transformation, therefore we can't map offsets without
knowledge of the specific transformation.
* ProcessRotateLeft: tell() offsets would be decreasing, which could
cause all sorts of problems.
In both those cases, it makes more sense for the user to use a Tell
immediately before the Transformed or ProcessRotateLeft and do their own
mapping.
Imagine we have this simple example where we want to record the position of the "payload" object within our file to be able to reference it:
In that example,
payload_position
is 4, as expected. Our payload starts at byte index 4 in the parsed stream.Now, let's write an alternative version using Prefixed(), which a user could expect to be functionally equivalent:
Oops,
payload_position=0
. We lost track of the position of the payload. That's not a very usefulTell
in this case.The reason is
Tell
reliesstream.tell()
, and several subconstructs createio.BytesIO()
from data read from the original substream, which makesstream.tell()
return 0. Furthermore, as far as I've been able to find, the position of the parent stream at the time of creating theBytesIO
is not recorded, so this information cannot be recovered from theContainer
.The text was updated successfully, but these errors were encountered: