fixed offset checking for empty files

This commit is contained in:
Frank Morgner
2012-09-14 15:09:01 +02:00
parent c263b1f9dc
commit 8b3d802cab

View File

@@ -699,7 +699,7 @@ class MF(DF):
def dataUnitsDecodePlain(self, p1, p2, data): def dataUnitsDecodePlain(self, p1, p2, data):
""" """
Decodes 'p1', 'p2' and 'data' from a data unit command (i. e. Decodes 'p1', 'p2' and 'data' from a data unit command (i. e.
read/write/update/search/erase binary) with *odd* instruction code. read/write/update/search/erase binary) with *even* instruction code.
:returns: the specified TransparentStructureEF, a list of offsets and a :returns: the specified TransparentStructureEF, a list of offsets and a
list of data strings. list of data strings.
@@ -725,7 +725,7 @@ class MF(DF):
def dataUnitsDecodeEncapsulated(self, p1, p2, data): def dataUnitsDecodeEncapsulated(self, p1, p2, data):
""" """
Decodes 'p1', 'p2' and 'data' from a data unit command (i. e. Decodes 'p1', 'p2' and 'data' from a data unit command (i. e.
read/write/update/search/erase binary) with *even* instruction code. read/write/update/search/erase binary) with *odd* instruction code.
:returns the specified TransparentStructureEF, a list of offsets and a :returns the specified TransparentStructureEF, a list of offsets and a
list of data strings. list of data strings.
@@ -1376,6 +1376,9 @@ class TransparentStructureEF(EF):
"""Returns the string of decrypted data beginning at 'offset'.""" """Returns the string of decrypted data beginning at 'offset'."""
data = self.data data = self.data
if offset == 0:
return data
else:
if offset + 1 > len(data): if offset + 1 > len(data):
raise SwError(SW["ERR_OFFSETOUTOFFILE"]) raise SwError(SW["ERR_OFFSETOUTOFFILE"])
@@ -1587,10 +1590,11 @@ class RecordStructureEF(EF):
records = self.__getRecords(num_id, reference) records = self.__getRecords(num_id, reference)
result = [] result = []
for r in records: for r in records:
result.append(r.data[offset:])
if offset == 0: if offset == 0:
pass result.append(r.data)
elif offset > 0 and offset > len(r.data): else:
result.append(r.data[offset:])
if offset > 0 and offset > len(r.data):
offset -= len(r.data) offset -= len(r.data)
else: else:
offset = 0 offset = 0