https://github.com/qutebrowser/qutebrowser/commit/1ee138b681a590ee500954361eed2cf923b1d8a0
From: Florian Bruhin <me@the-compiler.org>
Date: Mon, 25 Mar 2024 23:19:37 +0100
Subject: [PATCH] qtutils: Handle QDataStream.Status.SizeLimitExceeded
--- a/qutebrowser/utils/qtutils.py
+++ b/qutebrowser/utils/qtutils.py
@@ -193,6 +193,15 @@ def check_qdatastream(stream: QDataStream) -> None:
         QDataStream.Status.WriteFailed: ("The data stream cannot write to the "
                                   "underlying device."),
     }
+    try:
+        status_to_str[QDataStream.Status.SizeLimitExceeded] = (  # type: ignore[attr-defined]
+            "The data stream cannot read or write the data because its size is larger "
+            "than supported by the current platform."
+        )
+    except AttributeError:
+        # Added in Qt 6.7
+        pass
+
     if stream.status() != QDataStream.Status.Ok:
         raise OSError(status_to_str[stream.status()])
 
--- a/tests/unit/utils/test_qtutils.py
+++ b/tests/unit/utils/test_qtutils.py
@@ -208,6 +208,18 @@ def test_ensure_valid(obj, raising, exc_reason, exc_str):
      "The data stream has read corrupt data."),
     (QDataStream.Status.WriteFailed, True,
      "The data stream cannot write to the underlying device."),
+    pytest.param(
+        getattr(QDataStream.Status, "SizeLimitExceeded", None),
+        True,
+        (
+            "The data stream cannot read or write the data because its size is larger "
+            "than supported by the current platform."
+        ),
+        marks=pytest.mark.skipif(
+            not hasattr(QDataStream.Status, "SizeLimitExceeded"),
+            reason="Added in Qt 6.7"
+        )
+    ),
 ])
 def test_check_qdatastream(status, raising, message):
     """Test check_qdatastream.
@@ -226,10 +238,25 @@ def test_check_qdatastream(status, raising, message):
         qtutils.check_qdatastream(stream)
 
 
-def test_qdatastream_status_count():
-    """Make sure no new members are added to QDataStream.Status."""
-    status_vals = testutils.enum_members(QDataStream, QDataStream.Status)
-    assert len(status_vals) == 4
+def test_qdatastream_status_members():
+    """Make sure no new members are added to QDataStream.Status.
+
+    If this fails, qtutils.check_qdatastream will need to be updated with the
+    respective error documentation.
+    """
+    status_vals = set(testutils.enum_members(QDataStream, QDataStream.Status).values())
+    expected = {
+        QDataStream.Status.Ok,
+        QDataStream.Status.ReadPastEnd,
+        QDataStream.Status.ReadCorruptData,
+        QDataStream.Status.WriteFailed,
+    }
+    try:
+        expected.add(QDataStream.Status.SizeLimitExceeded)
+    except AttributeError:
+        # Added in Qt 6.7
+        pass
+    assert status_vals == expected
 
 
 @pytest.mark.parametrize('color, expected', [
