fix: bound actual table references
This commit is contained in:
@@ -46,7 +46,7 @@ describe('content table allocation safety', () => {
|
||||
expect.objectContaining({
|
||||
code: 'CONTENT_PARSE_FAILED',
|
||||
message: expect.stringContaining(
|
||||
'Declared table column count exceeds 1000000'
|
||||
`Declared table column count exceeds ${DEFAULT_ONENOTE_PARSER_LIMITS.maxTableCells}`
|
||||
),
|
||||
})
|
||||
);
|
||||
@@ -77,7 +77,43 @@ describe('content table allocation safety', () => {
|
||||
})
|
||||
).toEqual([]);
|
||||
expect(diagnostics[0]?.message).toContain(
|
||||
'Declared table cell count exceeds 1000000'
|
||||
`Declared table cell count exceeds ${DEFAULT_ONENOTE_PARSER_LIMITS.maxTableCells}`
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects actual row references before mapping an oversized array', () => {
|
||||
const tableId: ExGuid = { guid: GUID, value: 3 };
|
||||
const firstRowId: ExGuid = { guid: GUID, value: 4 };
|
||||
const secondRowId: ExGuid = { guid: GUID, value: 5 };
|
||||
const table = object(
|
||||
tableId,
|
||||
JCID.TableNode,
|
||||
props(referenceEntry(PROPERTY.ElementChildNodes, 2))
|
||||
);
|
||||
table.resolvedObjectIds = [firstRowId, secondRowId];
|
||||
const firstRow = object(firstRowId, JCID.TableRowNode, props());
|
||||
const secondRow = object(secondRowId, JCID.TableRowNode, props());
|
||||
const diagnostics: ParserDiagnostic[] = [];
|
||||
|
||||
expect(
|
||||
parseContentObjects([tableId], {
|
||||
space: {
|
||||
id: { guid: GUID, value: 0 },
|
||||
roots: new Map(),
|
||||
objects: new Map(
|
||||
[table, firstRow, secondRow].map((value) => [
|
||||
exGuidKey(value.id),
|
||||
value,
|
||||
])
|
||||
),
|
||||
},
|
||||
limits: { ...DEFAULT_ONENOTE_PARSER_LIMITS, maxTableCells: 1 },
|
||||
diagnostics,
|
||||
resources: new Map(),
|
||||
})
|
||||
).toEqual([]);
|
||||
expect(diagnostics[0]?.message).toContain(
|
||||
'Table row reference count exceeds 1'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -122,3 +158,12 @@ function bytesEntry(rawId: number, value: Uint8Array): PropertyEntry {
|
||||
value: { kind: 'bytes', value },
|
||||
};
|
||||
}
|
||||
|
||||
function referenceEntry(rawId: number, count: number): PropertyEntry {
|
||||
return {
|
||||
rawId,
|
||||
id: rawId & 0x03ff_ffff,
|
||||
type: 0x9,
|
||||
value: { kind: 'objectIds', count },
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user