fix: append large parser collections safely

This commit is contained in:
2026-07-22 19:59:59 +02:00
parent 622f1e94dd
commit 72b95c828a
4 changed files with 37 additions and 2 deletions

View File

@@ -0,0 +1,9 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0
/** Append a bounded collection without relying on the engine's argument cap. */
export function appendItems<T>(target: T[], items: readonly T[]): void {
for (const item of items) target.push(item);
}

View File

@@ -11,6 +11,7 @@
import { BinaryReader } from '../binary/BinaryReader.js';
import { filetimeToIso, oneNoteTimeToIso } from '../binary/time.js';
import { appendItems } from '../model/append.js';
import type { ParserDiagnostic } from '../model/diagnostics.js';
import type { OneNotePageSummaryDto, OneNoteSectionDto } from '../model/dto.js';
import type { OneNoteParserLimits } from '../parser/limits.js';
@@ -341,7 +342,10 @@ function traverseReferences(
): string[] {
const result: string[] = [];
for (const id of ids) {
result.push(...extractGraphText(context, space, id, active, depth + 1));
appendItems(
result,
extractGraphText(context, space, id, active, depth + 1)
);
}
return result;
}

View File

@@ -4,6 +4,7 @@
import { BinaryReader } from '../binary/BinaryReader.js';
import { readGuid } from '../binary/guid.js';
import { appendItems } from '../model/append.js';
import type { ParserDiagnostic } from '../model/diagnostics.js';
import { parseDesktopOneNoteTableOfContentsStore } from '../onestore/desktop-store.js';
import type { DesktopOneStore } from '../onestore/desktop-store.js';
@@ -171,7 +172,7 @@ function parseChildren(
color: optionalColor(child),
});
} else {
result.push(...parseChildren(context, child, depth + 1));
appendItems(result, parseChildren(context, child, depth + 1));
}
} finally {
context.active.delete(key);