Skip to content
This repository was archived by the owner on Mar 27, 2026. It is now read-only.

Commit b2db25a

Browse files
author
Ron Frenkel
committed
1. Fixed a bug in read_tag - is_continuation was called on the the next byte instead of the current byte.
2. When trying to read beyond end of buffer, return the tlv instead of data. This can happen when the data is padded.
1 parent 40b5b79 commit b2db25a

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

emv/protocol/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def read_tag(data):
4545
if is_two_byte(data[i]):
4646
i += 1
4747
tag += [data[i]]
48-
i += 1
4948
while len(data) > i and is_continuation(data[i]):
50-
tag += [data[i]]
5149
i += 1
50+
tag += [data[i]]
51+
i += 1
5252
else:
5353
i += 1
5454
return tag, i

emv/protocol/structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def unmarshal(cls, data):
4444
i += tag_len
4545
if len(data) <= i:
4646
log.info("Invalid TLV - read beyond end of buffer at %s: %s", tag, data)
47-
return data
47+
return tlv
4848
length = data[i]
4949
i += 1
5050
value = data[i : i + length]

emv/protocol/test/test_structures.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def test_tlv(self):
3131
tlv = TLV.unmarshal(data)
3232
self.assertEqual(tlv[(0x9F, 0x17)][0], 3)
3333

34+
data = unformat_bytes("DF DF 39 01 07")
35+
tlv = TLV.unmarshal(data)
36+
self.assertEqual(tlv[(0xDF, 0xDF, 0x39)][0], 7)
37+
3438
def test_duplicate_tags(self):
3539
# An ADF entry with a number of records:
3640
data = unformat_bytes(

0 commit comments

Comments
 (0)