fix: bound browser image previews
This commit is contained in:
124
src/onenote/one/content-table-safety.test.ts
Normal file
124
src/onenote/one/content-table-safety.test.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { ParserDiagnostic } from '../model/diagnostics.js';
|
||||
import { DEFAULT_ONENOTE_PARSER_LIMITS } from '../parser/limits.js';
|
||||
import type {
|
||||
ExGuid,
|
||||
ObjectPropSet,
|
||||
ObjectSpace,
|
||||
PropertyEntry,
|
||||
StoreObject,
|
||||
} from '../onestore/types.js';
|
||||
import { exGuidKey } from '../onestore/types.js';
|
||||
import { parseContentObjects } from './content.js';
|
||||
import { JCID, PROPERTY } from './constants.js';
|
||||
|
||||
const GUID = '{55555555-5555-5555-5555-555555555555}';
|
||||
|
||||
describe('content table allocation safety', () => {
|
||||
it('rejects a max-u32 declared column count before bitmap allocation', () => {
|
||||
const tableId: ExGuid = { guid: GUID, value: 1 };
|
||||
const table = object(
|
||||
tableId,
|
||||
JCID.TableNode,
|
||||
props(
|
||||
u32Entry(PROPERTY.RowCount, 1),
|
||||
u32Entry(PROPERTY.ColumnCount, 0xffff_ffff),
|
||||
bytesEntry(PROPERTY.TableColumnsLocked, Uint8Array.of(1, 1))
|
||||
)
|
||||
);
|
||||
const diagnostics: ParserDiagnostic[] = [];
|
||||
const space: ObjectSpace = {
|
||||
id: { guid: GUID, value: 0 },
|
||||
roots: new Map(),
|
||||
objects: new Map([[exGuidKey(table.id), table]]),
|
||||
};
|
||||
|
||||
expect(
|
||||
parseContentObjects([tableId], {
|
||||
space,
|
||||
limits: { ...DEFAULT_ONENOTE_PARSER_LIMITS },
|
||||
diagnostics,
|
||||
resources: new Map(),
|
||||
})
|
||||
).toEqual([]);
|
||||
expect(diagnostics).toContainEqual(
|
||||
expect.objectContaining({
|
||||
code: 'CONTENT_PARSE_FAILED',
|
||||
message: expect.stringContaining(
|
||||
'Declared table column count exceeds 1000000'
|
||||
),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects declared table dimensions whose product exceeds the cell limit', () => {
|
||||
const tableId: ExGuid = { guid: GUID, value: 2 };
|
||||
const table = object(
|
||||
tableId,
|
||||
JCID.TableNode,
|
||||
props(
|
||||
u32Entry(PROPERTY.RowCount, 1_001),
|
||||
u32Entry(PROPERTY.ColumnCount, 1_000)
|
||||
)
|
||||
);
|
||||
const diagnostics: ParserDiagnostic[] = [];
|
||||
|
||||
expect(
|
||||
parseContentObjects([tableId], {
|
||||
space: {
|
||||
id: { guid: GUID, value: 0 },
|
||||
roots: new Map(),
|
||||
objects: new Map([[exGuidKey(table.id), table]]),
|
||||
},
|
||||
limits: { ...DEFAULT_ONENOTE_PARSER_LIMITS },
|
||||
diagnostics,
|
||||
resources: new Map(),
|
||||
})
|
||||
).toEqual([]);
|
||||
expect(diagnostics[0]?.message).toContain(
|
||||
'Declared table cell count exceeds 1000000'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function object(
|
||||
id: ExGuid,
|
||||
jcid: number,
|
||||
objectProps: ObjectPropSet
|
||||
): StoreObject {
|
||||
return {
|
||||
id,
|
||||
jcid,
|
||||
props: objectProps,
|
||||
mapping: new Map(),
|
||||
contextId: { guid: GUID, value: 0 },
|
||||
};
|
||||
}
|
||||
|
||||
function props(...entries: PropertyEntry[]): ObjectPropSet {
|
||||
return {
|
||||
objectIds: [],
|
||||
objectSpaceIds: [],
|
||||
contextIds: [],
|
||||
properties: { entries },
|
||||
};
|
||||
}
|
||||
|
||||
function u32Entry(rawId: number, value: number): PropertyEntry {
|
||||
return {
|
||||
rawId,
|
||||
id: rawId & 0x03ff_ffff,
|
||||
type: 0x4,
|
||||
value: { kind: 'u32', value },
|
||||
};
|
||||
}
|
||||
|
||||
function bytesEntry(rawId: number, value: Uint8Array): PropertyEntry {
|
||||
return {
|
||||
rawId,
|
||||
id: rawId & 0x03ff_ffff,
|
||||
type: 0x7,
|
||||
value: { kind: 'bytes', value },
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user