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:
1 parent
d2376a4574
commit
b44dd80af2
4 files changed
+26
-9
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user