Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory-friendly cartridge format #37

Merged
merged 10 commits into from
Dec 26, 2023
Merged

Memory-friendly cartridge format #37

merged 10 commits into from
Dec 26, 2023

Conversation

cute-the-niini
Copy link
Member

This required some messing around with the cartridge format (again "Orz), but at least now it should stabilise (famous last words ahaha :'>). This is a breaking change as the parsers for previous versions was removed --- so existing cartridges need to be re-packaged with the new version to be installed.

There are quite a few things that this patch takes care of, though it doesn't solve all memory issues in Kate just yet:

  • Cartridges now have no (practical) size limitation, however individual files must fit entirely in memory, so there are practical limitations on those. The reason for this is because the browser cryptographic APIs that Kate uses for verifying the cartridge's contents do not (yet?) support streaming use cases, so the whole data needs to be load in memory anyway for integrity checking. The old 1.4GB arbitrary limit on the KART file size has been removed as a result of this. Installation and cartridge parsing requires O(max(f1.size, ..., fN.size)) space --- so the highest size of each individual file.

  • Theoretically file sizes for Kate on web are limited to 2**53, but that's 8192 TB so no real concern there. Cartridge offsets are Uint64 by the specification, but web APIs only support 64-bit floats for offsets and sizes.

  • Cartridge format is now friendly to stream-writing and random-access. By placing files first and the location header last in the file we don't have to back-patch any references and we have all necessary data to build a proper file location table with specific offsets into the binary. That means we can run a cartridge with a file reference without having to install it first, however Kate will continue to install cartridges as before.

  • That said, the importer doesn't make use of any of this yet because it has no disk storage to write data to. The partitioned file storage has to be reified as a user-land API in order for the importer (and the future publisher) to be able to create cartridges with bounded memory usage. Likewise, the installation API needs to change to take a file reference instead of arbitrary bytes.

There's some work that still needs to be done with signatures (they aren't verified yet! and you can't sign cartridges yet!). This does prepare things a bit. Cartridges can now be signed without relocating any files by overwriting only the metadata and header sections. Note that the metadata section is not fixed-size, so both sections need to be re-written if a cartridge is to be signed after-the-fact. Kate supports multiple signatures to be attached and they all sit in the same metadata section. Files are not signed directly, but the file offset table (with the locations and integrity hashes) is signed. This also avoids needing to keep files around for signing given web crypto API limitations.

@cute-the-niini cute-the-niini added enhancement New feature or request c:kernel Changes to the Kate emulator kernel (requires strict audits!) BREAKING CHANGE The patch is incompatible with previous versions of Kate labels Dec 26, 2023
@cute-the-niini cute-the-niini merged commit 4417268 into main Dec 26, 2023
1 check passed
@cute-the-niini cute-the-niini deleted the patch/stream-parser branch December 26, 2023 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE The patch is incompatible with previous versions of Kate c:kernel Changes to the Kate emulator kernel (requires strict audits!) enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant