// 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/. import { describe, expect, it } from 'vitest'; import { BinaryReader } from '../src/onenote/binary/BinaryReader.js'; import { parseObjectPropSet } from '../src/onenote/onestore/property-set.js'; import { OneNoteParserError } from '../src/onenote/parser/error.js'; import { resolveParserLimits } from '../src/onenote/parser/limits.js'; describe('bounded OneStore primitives', () => { it('reports an absolute offset instead of reading beyond its view', () => { const reader = new BinaryReader( Uint8Array.from([0, 1, 2, 3, 4, 5]), 2, 3, 'test view' ); expect(reader.u16()).toBe(0x0302); try { reader.u16(); expect.unreachable('the read should fail'); } catch (error) { expect(error).toBeInstanceOf(OneNoteParserError); expect(error).toMatchObject({ code: 'BOUNDS_EXCEEDED', offset: 4, structure: 'test view', }); } }); it('decodes a bounded object property set without reading Boolean bytes', () => { const bytes = Uint8Array.from([ 0x00, 0x00, 0x00, 0x80, // OID stream: zero IDs, OSID stream absent 0x02, 0x00, // two properties 0x01, 0x00, 0x00, 0x88, // Boolean true 0x02, 0x00, 0x00, 0x1c, // byte vector 0x03, 0x00, 0x00, 0x00, 0xaa, 0xbb, 0xcc, ]); const parsed = parseObjectPropSet( bytes, { offset: 0, size: bytes.length, nil: false, zero: false }, resolveParserLimits() ); expect(parsed.properties.entries[0]?.value).toEqual({ kind: 'bool', value: true, }); expect(parsed.properties.entries[1]?.value).toMatchObject({ kind: 'bytes', value: Uint8Array.from([0xaa, 0xbb, 0xcc]), }); }); });