[Git][reproducible-builds/diffoscope][master] Do not run jsondiff on files over 100KiB as the algorithm runs in O(n^2) time....

Chris Lamb (@lamby) gitlab at salsa.debian.org
Mon Aug 18 19:46:24 UTC 2025



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
937c2199 by Chris Lamb at 2025-08-18T12:46:01-07:00
Do not run jsondiff on files over 100KiB as the algorithm runs in O(n^2) time. (Closes: reproducible-builds/diffoscope#414)

- - - - -


1 changed file:

- diffoscope/comparators/json.py


Changes:

=====================================
diffoscope/comparators/json.py
=====================================
@@ -18,6 +18,7 @@
 
 import re
 import json
+import os
 import pprint
 import logging
 import collections
@@ -85,6 +86,15 @@ class JSONFile(File):
         if jsondiff is None:
             return
 
+        # Ignore files over 100 KiB as jsondiff scales in O(n^2) time.
+        # <https://github.com/xlwings/jsondiff/issues/73>
+        limit = 100 * 1024
+        if (
+            os.stat(self.path).st_size > limit
+            or os.stat(other.path).st_size > limit
+        ):
+            return
+
         logger.debug(f"Comparing using jsondiff {jsondiff.__version__}")
 
         a = getattr(self, "parsed", {})



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/937c219959c4b3a81745b359a5d59ee4e3a9542c

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/937c219959c4b3a81745b359a5d59ee4e3a9542c
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20250818/f6f3d24e/attachment.htm>


More information about the rb-commits mailing list