Skip to content

Commit

Permalink
improved ber length decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
markreidvfx committed Apr 12, 2024
1 parent c1d681c commit 1fd39a7
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/aaf2/mxf.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,14 +833,22 @@ def link(self):
return tag

def ber_length(f):
length = read_u8(f)
if length > 127:
data = bytearray(length - 128)
bytes_read = f.readinto(data)
assert bytes_read == len(data)
length = int_from_bytes(data, byte_order='big')
return length

b = read_u8(f)
if b == 0x80:
# unknown length
result = 0
elif b & 0x80 != 0x80:
# short form
result = b
else:
# long form
length = b & 0x7f
result = 0
for _ in range(length):
b = read_u8(f)
result = (result << 8) + b

return result

def iter_kl(f):
pos = f.tell()
Expand Down

0 comments on commit 1fd39a7

Please sign in to comment.