laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/pysim/+/43987?usp=email )

Change subject: esim.saip: expand a record template's default value per record
......................................................................

esim.saip: expand a record template's default value per record

FileTemplate.expand_default_value_pattern() expanded the default once
across the requested length. The SAIP templates give a linear fixed or
cyclic file its default per record (EF.ICI: 20 records of 38 bytes,
'FF...FF0000000001FFFF'), so only the last record received the tail of
the default.

When more than one record is asked for, expand one record and repeat
it. A transparent file, a single record and a literal default that
does not fill its record are unchanged.

The folder osmocom-pysim-saip-fill-file-offset-erased-state of
hampushellsberg-dev/PySIM-upstream-patches on GitHub has the analysis
and a repro.

Change-Id: Icff87219718422f11c9924485d2c4d4090381a45
---
M pySim/esim/saip/templates.py
1 file changed, 13 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved




diff --git a/pySim/esim/saip/templates.py b/pySim/esim/saip/templates.py
index 5dfe375..cad5e2c 100644
--- a/pySim/esim/saip/templates.py
+++ b/pySim/esim/saip/templates.py
@@ -116,11 +116,23 @@
             return self.rec_len

     def expand_default_value_pattern(self, length: Optional[int] = None) -> 
Optional[bytes]:
-        """Expand the default value pattern to the specified length."""
+        """Expand the default value pattern to the specified length.
+
+        The SAIP section 9 tables give a linear-fixed or cyclic file its 
default per record
+        (EF ICI: 20 records of 38 bytes, default 'FF...FF0000000001FFFF'), 
which is what
+        _default_value_len already assumes. A request longer than one record 
therefore expands
+        one record and repeats it; expanding once across the file puts the 
tail of the default
+        into the last record only.
+        """
         if length is None:
             length = self._default_value_len()
         if length is None:
             raise ValueError("%s does not have a default length" % self)
+        if self.file_type in ['LF', 'CY'] and self.rec_len and length > 
self.rec_len:
+            record = self.expand_default_value_pattern(self.rec_len)
+            if record and len(record) == self.rec_len:
+                count, rest = divmod(length, self.rec_len)
+                return record * count + record[:rest]
         if not self.default_val:
             return None
         if not '...' in self.default_val:

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/43987?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Icff87219718422f11c9924485d2c4d4090381a45
Gerrit-Change-Number: 43987
Gerrit-PatchSet: 4
Gerrit-Owner: laforge <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <[email protected]>
Gerrit-Reviewer: jolly <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-CC: hampushellsberg <[email protected]>

Reply via email to