From 0d5ba595d6a5b31f47ed57780779302495c1c8c0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 8 Apr 2026 23:43:02 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Fix=20O(N^2)=20vector=20erasure=20i?= =?UTF-8?q?n=20ISO=20demuxer=20error=20recovery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored the sample chunk validation loop in `ErrorRecovery::RepairSampleToChunkTable` to use the erase-remove idiom instead of repeatedly calling `vector::erase` inside a loop. This replaces O(N^2) shifting operations with an O(N) single-pass shift. The duplicate logging behavior has been intentionally maintained by comparing container sizes pre- and post-erasure and logging proportionally. Co-authored-by: segin <480709+segin@users.noreply.github.com> --- src/demuxer/iso/ErrorRecovery.cpp | 20 ++++++++++++-------- util/build-deps.sh | 0 2 files changed, 12 insertions(+), 8 deletions(-) mode change 100644 => 100755 util/build-deps.sh diff --git a/src/demuxer/iso/ErrorRecovery.cpp b/src/demuxer/iso/ErrorRecovery.cpp index 19183790..c0281244 100644 --- a/src/demuxer/iso/ErrorRecovery.cpp +++ b/src/demuxer/iso/ErrorRecovery.cpp @@ -199,14 +199,18 @@ bool ErrorRecovery::RepairSampleToChunkTable(SampleTableInfo& tables) { } // Check for invalid entries in sample-to-chunk table - for (auto it = tables.sampleToChunkEntries.begin(); it != tables.sampleToChunkEntries.end(); ) { - if (it->samplesPerChunk == 0 || it->sampleDescIndex == 0) { - // Invalid entry, remove it - it = tables.sampleToChunkEntries.erase(it); - LogError("ChunkTableRepair", "Removed invalid sample-to-chunk entry"); - } else { - ++it; - } + size_t originalSize = tables.sampleToChunkEntries.size(); + tables.sampleToChunkEntries.erase( + std::remove_if(tables.sampleToChunkEntries.begin(), tables.sampleToChunkEntries.end(), + [](const auto& entry) { + return entry.samplesPerChunk == 0 || entry.sampleDescIndex == 0; + }), + tables.sampleToChunkEntries.end() + ); + + size_t removedCount = originalSize - tables.sampleToChunkEntries.size(); + for (size_t i = 0; i < removedCount; ++i) { + LogError("ChunkTableRepair", "Removed invalid sample-to-chunk entry"); } // If all entries were invalid, create a default entry diff --git a/util/build-deps.sh b/util/build-deps.sh old mode 100644 new mode 100755