fix(domain): R4.5 gate hardenings: self-check without the import size cap, Ref(0) safe, pdf-write implies pdf-read; §10.7 records the gate

This commit is contained in:
bchanot committed 2026-10-18 23:39:31 +02:00
1 parent d2376a4574
commit b44dd80af2
4 files changed
+26 -9

No files matched your search

+1 -1
View File
@@ -18,7 +18,7 @@ ts = ["dep:ts-rs"]
# facade enables it; the worker never does.
pdf-read = ["dep:miniz_oxide"]
# The PDF writer (R4, plan §B.1.3): layout to a draw log (R4.4), the serialiser (R4.5).
pdf-write = []
pdf-write = ["pdf-read"]
[dependencies]
serde.workspace = true
+8 -7
View File
@@ -12,7 +12,7 @@ use super::serialize::{Document, Metadata, export_date, serialize};
use crate::domain::archive::{EnvelopeFormat, EnvelopeVersion1, Locale, ReportArchiveEnvelope};
use crate::json::to_js_pretty;
use crate::pdf::read::MAX_ATTACHMENT_BYTES;
use crate::pdf::read::probe::{ProbeLimits, read_attached_document};
use crate::pdf::read::probe::{ProbeLimits, locate_attachment};
/// What an export gives back: the file, the envelope text it carries and the warnings.
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -49,13 +49,14 @@ fn envelope_text(input: &CheckedInput) -> Result<String, ExportError> {
}
/// `finish()` re-reads its own output: one scan and one inflation, the attachment's text
/// against the envelope written.
/// against the envelope written. The scan runs without the reader's 50 MiB file cap: a
/// larger export (a report near the caps with real rasters) is a valid file that the import
/// refuses by size, as the TypeScript's did (plan §B.1.2); the export is not where to refuse it.
fn self_check(pdf: &[u8], envelope: &str) -> Result<(), ExportError> {
let located =
read_attached_document(pdf, ProbeLimits::PRODUCTION).map_err(|kind| ExportError {
kind: ExportErrorKind::SelfCheckFailed,
detail: kind.as_str().to_owned(),
})?;
let located = locate_attachment(pdf, ProbeLimits::PRODUCTION).map_err(|kind| ExportError {
kind: ExportErrorKind::SelfCheckFailed,
detail: kind.as_str().to_owned(),
})?;
if located.text != envelope {
return Err(ExportError {
kind: ExportErrorKind::SelfCheckFailed,
+1 -1
View File
@@ -34,7 +34,7 @@ impl Objects {
}
pub fn set(&mut self, at: Ref, body: Vec<u8>) {
if let Some(slot) = self.bodies.get_mut(at.0 - 1) {
if let Some(slot) = at.0.checked_sub(1).and_then(|i| self.bodies.get_mut(i)) {
*slot = body;
}
}