mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-20 09:15:26 +00:00
hayro-syntax: skip a dictionary entry whose value does not parse (#165)
Dict validates a dictionary by skipping its values, and the skip accepts some values that the parser cannot read: a name with a broken # escape (/#zz), a number such as 12-.5, and a dictionary followed by stream with no endstream. Dict::entries and Dict's Debug output unwrapped the result of parsing every value, so either one panicked on such a dictionary. Port LaurenzV/hayro#1501 to the vendored copy: entries skips an entry whose value does not parse, and Debug prints the entries. ArrayIter::next already ends the iteration on such an item here. Add LaurenzV/hayro#1501's two tests, update the local hashes of dict.rs and array.rs and the repair list in SOURCE.json, and note the change in vendor/README.craft-reader.md.
This commit is contained in:
1 parent
69c268014e
commit
9d17829194
4 files changed
+24
-19
No files matched your search
Vendored
+2
@@ -111,6 +111,8 @@ The implementation replays bounded source operands without allocating a glyph bu
|
||||
The existing Type 3 single-paint behavior and incomplete-content diagnostics remain.
|
||||
Raw array iteration now ends safely if validation and object parsing disagree;
|
||||
standalone sign tokens retain the reader's zero tolerance.
|
||||
`Dict::entries` and a dictionary's `Debug` output skip an entry whose value does not parse,
|
||||
as in [Hayro #1501](https://github.com/LaurenzV/hayro/pull/1501).
|
||||
Byte transfer-function samples use rounded 8-bit values; failed or non-finite evaluations
|
||||
leave the sample unchanged. Historical source hashes remain in each `SOURCE.json`,
|
||||
alongside local hashes and the compatibility reference.
|
||||
|
||||
Vendored
+4
-3
@@ -212,7 +212,7 @@
|
||||
"path": "src/object/array.rs",
|
||||
"source_sha256": "6fbddf05724848db2389068a0504cff6b0783e35baa58e64bf2a31d48a1042ea",
|
||||
"source_git_blob": "d39230f7dbf114dd202a16b21f7a6bb70be5ead3",
|
||||
"sha256": "36e937b44ca020e1b4846a47e8126bcf141d8fe1ba084690f17a4878861f7f7d"
|
||||
"sha256": "4537ab5cc06383e8b1e0dc97ae9fa1ee2869201615a37dea26bd0665006b2dd0"
|
||||
},
|
||||
{
|
||||
"path": "src/object/bool.rs",
|
||||
@@ -230,7 +230,7 @@
|
||||
"path": "src/object/dict.rs",
|
||||
"source_sha256": "bcfefabe931614b79ea54940d02fce534eb2363f1b75a03d6428fd7a04c57981",
|
||||
"source_git_blob": "1e016b567e8ec17801fa8282c47f653092839cb5",
|
||||
"sha256": "c53c686b05163fcb714d1ddacc8c55d340f745c29fead38f38d3c6b691673730"
|
||||
"sha256": "dac4329027aacb68c937fb2aa4b839960e0a94b6af40c4176b614ffa48157933"
|
||||
},
|
||||
{
|
||||
"path": "src/object/indirect.rs",
|
||||
@@ -370,6 +370,7 @@
|
||||
},
|
||||
"local_safety_repairs": [
|
||||
"Match existing standalone-plus-as-zero tolerance in number parsing while retaining regular-character terminator rejection and numeric overflow guards.",
|
||||
"End raw array iteration on object parse failure instead of panicking when validation and parsing differ."
|
||||
"End raw array iteration on object parse failure instead of panicking when validation and parsing differ.",
|
||||
"Skip a dictionary entry whose value does not parse in Dict::entries and Dict's Debug output instead of panicking, as in LaurenzV/hayro#1501 (23a8e290d4195ab31f737c12a1b079c114cdd13c)."
|
||||
]
|
||||
}
|
||||
+5
@@ -440,4 +440,9 @@ mod tests {
|
||||
assert!(matches!(res[0], Object::String(_)));
|
||||
assert!(matches!(res[1], Object::Name(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array_with_unreadable_item() {
|
||||
let _ = array_ref_impl(b"[true /#zz false]");
|
||||
}
|
||||
}
|
||||
+13
-16
@@ -100,10 +100,9 @@ impl<'a> Dict<'a> {
|
||||
pub fn entries(&self) -> impl Iterator<Item = (Name<'a>, MaybeRef<Object<'a>>)> + '_ {
|
||||
let mut sorted_keys = self.keys().collect::<Vec<_>>();
|
||||
sorted_keys.sort_by(|n1, n2| n1.as_ref().cmp(n2.as_ref()));
|
||||
sorted_keys.into_iter().map(|k| {
|
||||
let obj = self.get_raw(k.deref()).unwrap();
|
||||
(k, obj)
|
||||
})
|
||||
sorted_keys
|
||||
.into_iter()
|
||||
.filter_map(|k| self.get_raw(k.deref()).map(|obj| (k, obj)))
|
||||
}
|
||||
|
||||
/// Return the object identifier of the dict, if it's an indirect object.
|
||||
@@ -158,17 +157,8 @@ impl Debug for Dict<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||
let mut debug_struct = f.debug_struct("Dict");
|
||||
|
||||
if let Some(offsets) = self.offsets() {
|
||||
let mut r = Reader::new(self.data());
|
||||
|
||||
for (key, val) in offsets {
|
||||
r.jump(*val);
|
||||
debug_struct.field(
|
||||
&format!("{:?}", key.as_str()),
|
||||
&r.read_with_context::<MaybeRef<Object<'_>>>(&ReaderContext::dummy())
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
for (key, value) in self.entries() {
|
||||
debug_struct.field(&format!("{:?}", key.as_str()), &value);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1268,7 +1258,7 @@ mod tests {
|
||||
use crate::object::dict::keys::{COLORSPACE, EXT_G_STATE, FONT, PROC_SET};
|
||||
use crate::object::dict::{Dict, InlineImageDict};
|
||||
use crate::object::string;
|
||||
use crate::object::{Name, ObjRef};
|
||||
use crate::object::{FromBytes, Name, ObjRef};
|
||||
use crate::reader::Reader;
|
||||
use crate::reader::{ReaderContext, ReaderExt};
|
||||
|
||||
@@ -1411,4 +1401,11 @@ mod tests {
|
||||
assert_eq!(dict.get_ref("GS2"), Some(ObjRef::new(14, 0)));
|
||||
assert_eq!(dict.get_ref("GS3"), Some(ObjRef::new(15, 0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dict_with_unreadable_value() {
|
||||
let dict = Dict::from_bytes(b"<< /A /#zz /B true >>").unwrap();
|
||||
let _ = dict.entries().count();
|
||||
let _ = alloc::format!("{dict:?}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user