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
I expect variable_datum to serialize without an error, and for the final print to display the serialized object (should be b'\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\xff\xff\xff\xff')
Actual Behavior
The script throws a struct.error when variable_datum tries to serialize.
Full error
This is the full error that is thrown when variable_datum tries to serialize.
Traceback (most recent call last):
File "test.py", line 12, in <module>
variable_datum.serialize(outputStream)
File "C:\Users\e389403\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\dis7.py", line 3586, in serialize
outputStream.write_byte(self.variableData[x])
File "C:\Users\e389403\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\DataOutputStream.py", line 17, in write_byte
self.stream.write(struct.pack('b', val))
struct.error: byte format requires -128 <= number <= 127
Possible solutions
From what I can gather, when serialize is called:
serialize() is called
for each byte in the variableDatabytes object, it calls outputStream.write_byte())
This means that when it reaches b'\xff's, it tries to write 255 as a signed byte to outputStream.
thus it tries to call struct.pack('b', 255) which results in an error, rightly so because it's out of range(0, 256).
When I changed dis7.py line 3586 to outputStream.write_unsigned_byte(self.variableData[x]), then I got the expected behavior.
Notes
Signed integers actually parse without error. This makes sense, since inputStream.read_byte() is used to parse the bytes when forming the variableData list.
VariableDatum
objects throwstruct.error
when you try to store negative signed integers (e.g.-1
=b'\xff'
) in thevariableData
field, then serialize.MVP
This is the minimum viable product to reproduce the error
Expected Behavior
I expect
variable_datum
to serialize without an error, and for the finalprint
to display the serialized object (should beb'\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\xff\xff\xff\xff'
)Actual Behavior
The script throws a
struct.error
whenvariable_datum
tries to serialize.Full error
This is the full error that is thrown when
variable_datum
tries to serialize.Possible solutions
From what I can gather, when
serialize
is called:serialize()
is calledvariableData
bytes
object, it callsoutputStream.write_byte()
)This means that when it reaches
b'\xff'
s, it tries to write255
as a signed byte tooutputStream
.struct.pack('b', 255)
which results in an error, rightly so because it's out ofrange(0, 256)
.When I changed
dis7.py
line 3586 tooutputStream.write_unsigned_byte(self.variableData[x])
, then I got the expected behavior.Notes
Signed integers actually parse without error. This makes sense, since
inputStream.read_byte()
is used to parse the bytes when forming thevariableData
list.The text was updated successfully, but these errors were encountered: