Fix invalid DEFINED BY offset calculation for EXPL tagged objects 2.1
authorSergey Matveev <stargrave@stargrave.org>
Tue, 23 Jan 2018 09:04:17 +0000 (12:04 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 23 Jan 2018 09:04:17 +0000 (12:04 +0300)
VERSION
doc/news.rst
pyderasn.py
tests/test_pyderasn.py

diff --git a/VERSION b/VERSION
index cd5ac039d67e0bdadb17976e4ac39f0ffe6bb6e4..879b416e609a820dafeff67d679a7e3849fe8a09 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.0
+2.1
index 692f5cc87ab8ec8bb684704acc416f0b62bd0ee6..e935e0e8b6a18b27a1f739ec158be08b6ccd8021 100644 (file)
@@ -1,6 +1,13 @@
 News
 ====
 
 News
 ====
 
+.. _release2.1:
+
+2.1
+---
+* Fixed invalid offset calculation when dealing with DEFINED BY objects
+  having explicit tags
+
 .. _release2.0:
 
 2.0
 .. _release2.0:
 
 2.0
index e6c7fefab199266370c3f420d5469cf17a28a4a7..cd96a33200a1a6a7a801bc29b6aa95ca48b860cf 100755 (executable)
@@ -3875,7 +3875,10 @@ class Sequence(Obj):
                         )
                         defined_value, defined_tail = defined_spec.decode(
                             memoryview(bytes(_value)),
                         )
                         defined_value, defined_tail = defined_spec.decode(
                             memoryview(bytes(_value)),
-                            sub_offset + value.tlen + value.llen,
+                            sub_offset + (
+                                (value.tlen + value.llen + value.expl_tlen + value.expl_llen)
+                                if value.expled else (value.tlen + value.llen)
+                            ),
                             leavemm=True,
                             decode_path=sub_sub_decode_path,
                             ctx=ctx,
                             leavemm=True,
                             decode_path=sub_sub_decode_path,
                             ctx=ctx,
@@ -3891,7 +3894,10 @@ class Sequence(Obj):
                 else:
                     defined_value, defined_tail = defined_spec.decode(
                         memoryview(bytes(value)),
                 else:
                     defined_value, defined_tail = defined_spec.decode(
                         memoryview(bytes(value)),
-                        sub_offset + value.tlen + value.llen,
+                        sub_offset + (
+                            (value.tlen + value.llen + value.expl_tlen + value.expl_llen)
+                            if value.expled else (value.tlen + value.llen)
+                        ),
                         leavemm=True,
                         decode_path=sub_decode_path + (decode_path_defby(defined_by),),
                         ctx=ctx,
                         leavemm=True,
                         decode_path=sub_decode_path + (decode_path_defby(defined_by),),
                         ctx=ctx,
index 317ed91b078e30ab36d3f96a9e2877c26189b89c..13322d7b454679e13d5f9e97d40fb9313729a12e 100644 (file)
@@ -5003,6 +5003,9 @@ class TestDefinesByPath(TestCase):
         self.assertIsNotNone(seq_integered["value"].defined)
         self.assertEqual(seq_integered["value"].defined[0], type_integered)
         self.assertEqual(seq_integered["value"].defined[1], Integer(123))
         self.assertIsNotNone(seq_integered["value"].defined)
         self.assertEqual(seq_integered["value"].defined[0], type_integered)
         self.assertEqual(seq_integered["value"].defined[1], Integer(123))
+        self.assertTrue(seq_integered_raw[
+            seq_integered["value"].defined[1].offset:
+        ].startswith(Integer(123).encode()))
 
         seq_sequenced, _ = Seq().decode(
             seq_sequenced_raw,
 
         seq_sequenced, _ = Seq().decode(
             seq_sequenced_raw,