Compare commits

..

No commits in common. "c8" and "c9-beta" have entirely different histories.
c8 ... c9-beta

4 changed files with 65 additions and 141 deletions

4
.gitignore vendored
View File

@ -1,2 +1,2 @@
SOURCES/v0.1.5.tar.gz
SOURCES/v0.3.7.tar.gz
SOURCES/v0.2.8.tar.gz
SOURCES/v0.4.8.tar.gz

View File

@ -1,2 +1,2 @@
056d811a9a6a3a672fdeb3dd09bb17bc30968997 SOURCES/v0.1.5.tar.gz
a38478ac81d5b88caee1d92ce14185f34303890b SOURCES/v0.3.7.tar.gz
c8018d2eb53c51a74e955b7fdecda59e79f6f001 SOURCES/v0.2.8.tar.gz
41b65e2570a515b016708c6d72f652c8a742dc05 SOURCES/v0.4.8.tar.gz

View File

@ -1,122 +0,0 @@
From b111e63bd3b86ca9747b1bbb3f7eae7b9c01a82e Mon Sep 17 00:00:00 2001
From: Masahiro Matsuya <mmatsuya@redhat.com>
Date: Wed, 18 Feb 2026 13:54:42 +0900
Subject: [PATCH] Backport commit be353d7
Add limit of 20 continuation octets per OID arc to prevent a potential memory
exhaustion from excessive continuation bytes input.
---
pyasn1/codec/ber/decoder.py | 11 ++++++
tests/codec/ber/test_decoder.py | 66 +++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/pyasn1/codec/ber/decoder.py b/pyasn1/codec/ber/decoder.py
index ee3064f..69c9ecd 100644
--- a/pyasn1/codec/ber/decoder.py
+++ b/pyasn1/codec/ber/decoder.py
@@ -14,6 +14,10 @@ __all__ = ['decode']
noValue = base.noValue
+# Maximum number of continuation octets (high-bit set) allowed per OID arc.
+# 20 octets allows up to 140-bit integers, supporting UUID-based OIDs
+MAX_OID_ARC_CONTINUATION_OCTETS = 20
+
class AbstractDecoder(object):
protoComponent = None
@@ -284,7 +288,14 @@ class ObjectIdentifierDecoder(AbstractSimpleDecoder):
# Construct subid from a number of octets
nextSubId = subId
subId = 0
+ continuationOctetCount = 0
while nextSubId >= 128:
+ continuationOctetCount += 1
+ if continuationOctetCount > MAX_OID_ARC_CONTINUATION_OCTETS:
+ raise error.PyAsn1Error(
+ 'OID arc exceeds maximum continuation octets limit (%d) '
+ 'at position %d' % (MAX_OID_ARC_CONTINUATION_OCTETS, index)
+ )
subId = (subId << 7) + (nextSubId & 0x7F)
if index >= substrateLen:
raise error.SubstrateUnderrunError(
diff --git a/tests/codec/ber/test_decoder.py b/tests/codec/ber/test_decoder.py
index 5ec3a5f..ba7dfec 100644
--- a/tests/codec/ber/test_decoder.py
+++ b/tests/codec/ber/test_decoder.py
@@ -403,6 +403,72 @@ class ObjectIdentifierDecoderTestCase(BaseTestCase):
0xB8, 0xCB, 0xE2, 0xB6, 0x47))
) == ((2, 999, 18446744073709551535184467440737095), null)
+ def testExcessiveContinuationOctets(self):
+ """Test that OID arcs with excessive continuation octets are rejected."""
+ # Create a payload with 25 continuation octets (exceeds 20 limit)
+ # 0x81 bytes are continuation octets, 0x01 terminates
+ malicious_payload = bytes([0x06, 26]) + bytes([0x81] * 25) + bytes([0x01])
+ try:
+ decoder.decode(malicious_payload)
+ except PyAsn1Error:
+ pass
+ else:
+ assert 0, 'Excessive continuation octets tolerated'
+
+ def testMaxAllowedContinuationOctets(self):
+ """Test that OID arcs at the maximum continuation octets limit work."""
+ # Create a payload with exactly 20 continuation octets (at limit)
+ # This should succeed
+ payload = bytes([0x06, 21]) + bytes([0x81] * 20) + bytes([0x01])
+ try:
+ decoder.decode(payload)
+ except PyAsn1Error:
+ assert 0, 'Valid OID with 20 continuation octets rejected'
+
+ def testOneOverContinuationLimit(self):
+ """Test boundary: 21 continuation octets (one over limit) is rejected."""
+ payload = bytes([0x06, 22]) + bytes([0x81] * 21) + bytes([0x01])
+ try:
+ decoder.decode(payload)
+ except PyAsn1Error:
+ pass
+ else:
+ assert 0, '21 continuation octets tolerated (should be rejected)'
+
+ def testExcessiveContinuationInSecondArc(self):
+ """Test that limit applies to subsequent arcs, not just the first."""
+ # First arc: valid simple byte (0x55 = 85, decodes to arc 2.5)
+ # Second arc: excessive continuation octets
+ payload = bytes([0x06, 27]) + bytes([0x55]) + bytes([0x81] * 25) + bytes([0x01])
+ try:
+ decoder.decode(payload)
+ except PyAsn1Error:
+ pass
+ else:
+ assert 0, 'Excessive continuation in second arc tolerated'
+
+ def testMultipleArcsAtLimit(self):
+ """Test multiple arcs each at the continuation limit work correctly."""
+ # Two arcs, each with 20 continuation octets (both at limit)
+ arc1 = bytes([0x81] * 20) + bytes([0x01]) # 21 bytes
+ arc2 = bytes([0x81] * 20) + bytes([0x01]) # 21 bytes
+ payload = bytes([0x06, 42]) + arc1 + arc2
+ try:
+ decoder.decode(payload)
+ except PyAsn1Error:
+ assert 0, 'Multiple valid arcs at limit rejected'
+
+ def testExcessiveContinuationWithMaxBytes(self):
+ """Test with 0xFF continuation bytes (maximum value, not just 0x81)."""
+ # 0xFF bytes are also continuation octets (high bit set)
+ malicious_payload = bytes([0x06, 26]) + bytes([0xFF] * 25) + bytes([0x01])
+ try:
+ decoder.decode(malicious_payload)
+ except PyAsn1Error:
+ pass
+ else:
+ assert 0, 'Excessive 0xFF continuation octets tolerated'
+
class RealDecoderTestCase(BaseTestCase):
def testChar(self):
--
2.52.0

View File

@ -1,20 +1,16 @@
%global module pyasn1
%global modules_version 0.1.5
%global modules_version 0.2.8
Name: python-pyasn1
Version: 0.3.7
Release: 6%{?dist}.1
Version: 0.4.8
Release: 6%{?dist}
Summary: ASN.1 tools for Python
License: BSD
Group: System Environment/Libraries
Source0: https://github.com/etingof/pyasn1/archive/v%{version}.tar.gz
Source1: https://github.com/etingof/pyasn1-modules/archive/v%{modules_version}.tar.gz
URL: http://pyasn1.sourceforge.net/
BuildArch: noarch
Patch1: 0001-Backport-commit-be353d7.patch
%description
This is an implementation of ASN.1 types and codecs in the Python programming
language.
@ -39,6 +35,7 @@ ASN.1 types modules for python3-pyasn1.
%package doc
Summary: Documentation for pyasn1
BuildRequires: make
BuildRequires: python3-sphinx
%description doc
@ -47,7 +44,6 @@ BuildRequires: python3-sphinx
%prep
%setup -n %{module}-%{version} -q -b1
%autopatch -p1
%build
@ -57,7 +53,7 @@ pushd ../pyasn1-modules-%{modules_version}
%py3_build
popd
pushd doc
pushd docs
PYTHONPATH=%{buildroot}%{python3_sitelib} make SPHINXBUILD=sphinx-build-3 html
popd
@ -86,16 +82,66 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} %{__python3} setup.py test
%files doc
%license LICENSE.rst
%doc doc/build/html/*
%doc docs/build/html/*
%changelog
* Wed Feb 18 2026 Masahiro Matsuya <mmatsuya@redhat.com> - 0.3.7-6.el8_10.1
- Resolves: RHEL-148145
* Tue Aug 10 2021 Mohan Boddu <mboddu@redhat.com> - 0.4.8-6
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688
* Mon Jul 09 2018 Petr Viktorin <pviktori@redhat.com> - 0.3.7-6
- Remove the python2 subpackage
* Fri Apr 16 2021 Mohan Boddu <mboddu@redhat.com> - 0.4.8-5
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937
* Sun Jun 17 2018 Miro Hrončok <mhroncok@redhat.com> - 0.3.7-5
* Wed Jan 27 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.8-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
* Wed Jul 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.8-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
* Sat May 23 2020 Miro Hrončok <mhroncok@redhat.com> - 0.4.8-2
- Rebuilt for Python 3.9
* Thu Jan 30 2020 Rob Crittenden <rcritten@redhat.com> - 0.4.8-1
- Update to 0.4.8 (#1747820)
- Update modules to 0.2.8
* Thu Jan 30 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.6-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
* Wed Oct 23 2019 Rob Crittenden <rcritten@redhat.com> - 0.4.6-3
- Remove python2 subpackages (#1764573)
* Thu Oct 03 2019 Miro Hrončok <mhroncok@redhat.com> - 0.4.6-2
- Rebuilt for Python 3.8.0rc1 (#1748018)
* Fri Aug 30 2019 Rob Crittenden <rcritten@redhat.com> - 0.4.6-1
- Update to 0.4.6 (#1742424)
- Update modules to 0.2.6
* Fri Aug 16 2019 Miro Hrončok <mhroncok@redhat.com> - 0.4.4-6
- Rebuilt for Python 3.8
* Fri Jul 26 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.4-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
* Sat Feb 02 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.4-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
* Tue Oct 16 2018 Rob Crittenden <rcritten@redhat.com> - 0.4.4-3
- Restore python2 subpackages
* Mon Oct 15 2018 Rob Crittenden <rcritten@redhat.com> - 0.4.4-2
- Add back accidentally removed buildrequires
* Mon Oct 15 2018 Rob Crittenden <rcritten@redhat.com> - 0.4.4-1
- Update to 0.4.4 (#1582010)
- Update modules to 0.2.2
- Drop python 2 subpackages
* Sat Jul 14 2018 Fedora Release Engineering <releng@fedoraproject.org>
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
* Tue Jun 19 2018 Miro Hrončok <mhroncok@redhat.com> - 0.3.7-5
- Use Python 3 Sphinx if with Python 3
- Cleanup