From 347873576a047fc599695525dcceee486b8027c8 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Thu, 29 Jan 2026 12:20:31 +0000 Subject: [PATCH] Don't bother compressing really large log files just to throw them away. (#5021) --- .../Sources/Services/BugReport/BugReportService.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ElementX/Sources/Services/BugReport/BugReportService.swift b/ElementX/Sources/Services/BugReport/BugReportService.swift index 9bbc5093e..9af74bee8 100644 --- a/ElementX/Sources/Services/BugReport/BugReportService.swift +++ b/ElementX/Sources/Services/BugReport/BugReportService.swift @@ -228,6 +228,15 @@ class BugReportService: NSObject, BugReportServiceProtocol { /// Zips a file creating chunks based on 10MB inputs. private func attachFile(at url: URL, to zippedFiles: inout Logs) throws { + // We check the compressed size to determine whether or not to attach the files. + // **However:** given our gzip library compresses in memory it is possible to OOM + // on files that will obviously be thrown away, so check the uncompressed size too. + let uncompressedSizeThreshold = maxUploadSize * 5 + if try FileManager.default.sizeForItem(at: url) > maxUploadSize { + MXLog.error("Uncompressed logs too large, skipping attachment: \(url.lastPathComponent)") + return + } + let fileHandle = try FileHandle(forReadingFrom: url) while let data = try fileHandle.readToEnd() {