mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-24 06:43:02 -06:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbd753094b | ||
|
|
a355eefefc |
@@ -0,0 +1,69 @@
|
||||
# Accessibility
|
||||
|
||||
Source: `standards/app-accessibility.md` in [storytold/craft-contrib](https://github.com/storytold/craft-contrib/blob/main/standards/app-accessibility.md); do not edit this copy directly. Propose changes to the shared statement in [`storytold/craft-contrib`](https://github.com/storytold/craft-contrib).
|
||||
|
||||
We want people who use screen readers, braille displays, screen magnifiers, voice control, high contrast, large text, reduced motion, or keyboard navigation to be able to get their work done in the Craft applications.
|
||||
|
||||
## Supported environments and how accessibility works
|
||||
|
||||
The Craft applications draw their own interface in Rust with `egui` and expose accessibility information through **AccessKit**:
|
||||
|
||||
- **Windows:** UI Automation (for tools such as NVDA, JAWS, and Narrator)
|
||||
- **macOS:** NSAccessibility (VoiceOver)
|
||||
- **Linux and FreeBSD:** AT-SPI (Orca)
|
||||
- **Web (WebAssembly):** Browser accessibility tree in modern evergreen browsers
|
||||
- **Display and motion:** Light and dark themes, along with ongoing work to honour system high-contrast, text-scaling, and reduced-motion settings
|
||||
- **Headless and command-line workflows:** Most Craft applications also ship a command-line and automation binary (`<app>-cli`) that can inspect and edit documents from a terminal without using the graphical interface; see [This application](#this-application) below
|
||||
|
||||
**Current status:** The Craft suite is in early-alpha development. We use WCAG 2.2 and W3C's [WCAG2ICT](https://www.w3.org/TR/wcag2ict-22/) as practical reference points for user needs ([RFC-0014](https://github.com/storytold/craft-contrib/blob/main/rfcs/0014-accessibility.md)), while manual testing with assistive technologies across every tool and surface is still in progress.
|
||||
|
||||
## Known limitations and workarounds
|
||||
|
||||
Shared framework improvements are tracked in [storytold/craft-libs#437](https://github.com/storytold/craft-libs/issues/437). Current suite-wide gaps include:
|
||||
|
||||
- **Custom drawn surfaces (canvases, pages, grids, timelines, node graphs, and layer lists):** Some custom-painted views do not yet publish complete `AccessKit` nodes, caret bounds for magnifiers, or editable states (for example, `AccessKit`'s Windows adapter reporting `Document` nodes as read-only, which can prevent typing echo in screen readers). *Workaround:* Use structured inspector panels where available, or run headless commands through `<app>-cli` when a task does not need direct canvas interaction.
|
||||
- **Focus in menus, toolbars, and dialogs:** Some popups, menus, or keyboard access-key overlays may leave focus in the underlying document or not yet restore focus cleanly when dismissed. *Workaround:* Press `Escape` to close open popups, `Alt` or `F10` for menu/toolbar navigation, and `F6` to move between major regions where supported.
|
||||
- **Unannounced state changes:** Shortcuts or background tasks that change state away from focus do not yet consistently announce updates through a live region.
|
||||
- **Pointer-heavy interactions:** Certain timeline, node-wiring, or object-placement gestures do not yet have non-dragging keyboard alternatives.
|
||||
|
||||
See [This application](#this-application) below for repository-specific links and details.
|
||||
|
||||
## Reporting an accessibility barrier
|
||||
|
||||
If you run into an accessibility barrier, please open an issue using the link in [This application](#this-application) below (or let us know in the [ArtCraft Discord](https://discord.gg/artcraft) if GitHub's issue form gets in the way).
|
||||
|
||||
- **No personal disclosure needed:** You never have to disclose a disability or explain why you use assistive technology.
|
||||
- **Screenshots and recordings are optional:** Plain-text descriptions are always welcome and sufficient.
|
||||
- **Helpful details to share (when convenient):**
|
||||
- What you were trying to do, what happened, and what you expected
|
||||
- Application version (or commit) and operating system or browser
|
||||
- Input method, display settings, or assistive technology and version (for example, NVDA, JAWS, Narrator, VoiceOver, Orca, screen magnifier, high contrast, text scaling, or keyboard-only)
|
||||
|
||||
## How we respond
|
||||
|
||||
- **Triage and labels:** Maintainers and triagers label barrier reports with `accessibility` and set priority during triage based on impact—barriers that block a core workflow are treated as high-priority bugs, and barriers that risk losing work are critical.
|
||||
- **Assistive-technology verification (`needs screen reader test`):** Pull requests that fix a reported assistive-technology barrier or add custom accessibility-tree or focus behaviour are labelled `needs screen reader test` so someone using assistive technology can verify a build and share what they observed; if the barrier remains, we reopen the issue.
|
||||
|
||||
## Note for contributors and coding agents
|
||||
|
||||
`ACCESSIBILITY.md` is a user-facing overview, **not** an extra rule set or audit checklist for coding agents:
|
||||
|
||||
- **Follow `AGENTS.md` and [`standards/accessibility.md`](https://github.com/storytold/craft-contrib/blob/main/standards/accessibility.md) for engineering work,** and keep every pull request scoped strictly to its issue. Do not widen an unrelated change to audit or rework surrounding UI.
|
||||
- **Design for the actual user need—do not overbuild or apply naive readings of standards.** Accessibility guidelines exist to support real workflows and give flexible ways to meet them. Understand what a criterion genuinely requires in context before changing UI: for example, a button whose label or icon is legible and whose focus or selection ring already has clear contrast does **not** need its resting fill or border restyled to hit a 3:1 ratio, and inherently spatial or freehand tools should not have artificial keyboard grids bolted onto them.
|
||||
- **Preserve visual design and shared primitives.** Use shared theme tokens and shared widgets from `storytold/craft-libs` instead of inventing one-off styling, contrast overrides, focus shims, or live-region scaffolding inside an application.
|
||||
- **Be candid in pull requests.** Automated accessibility-tree checks never prove a change works with a real screen reader; describe only what was actually verified.
|
||||
|
||||
## Ownership
|
||||
|
||||
Maintained by the `craft-app-team` maintainers in [`storytold`](https://github.com/storytold). Shared updates belong in [`storytold/craft-contrib`](https://github.com/storytold/craft-contrib); repository-specific facts follow below.
|
||||
|
||||
## This application
|
||||
|
||||
**GridCraft** (`storytold/gridcraft`) is an open-source spreadsheet application written in pure Rust.
|
||||
|
||||
- **Published application builds:** macOS, Windows, Linux, FreeBSD, and Web (WebAssembly)
|
||||
- **Command-line and automation interface:** `gridcraft-cli` provides headless terminal and automation access for scripted workflows without the graphical interface
|
||||
- **Report an accessibility barrier:** [Open an issue in `storytold/gridcraft`](https://github.com/storytold/gridcraft/issues/new)
|
||||
- **Tracked accessibility issues:** [Open issues labelled `accessibility` in `storytold/gridcraft`](https://github.com/storytold/gridcraft/issues?q=is%3Aissue+state%3Aopen+label%3Aaccessibility)
|
||||
- **Pull requests awaiting assistive-technology verification:** [Pull requests labelled `needs screen reader test` in `storytold/gridcraft`](https://github.com/storytold/gridcraft/pulls?q=is%3Apr+label%3A%22needs+screen+reader+test%22)
|
||||
- **Contributor and agent rules for this repository:** [`AGENTS.md`](AGENTS.md)
|
||||
Generated
+42
-21
@@ -195,6 +195,15 @@ version = "1.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
|
||||
|
||||
[[package]]
|
||||
name = "arbitrary"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed"
|
||||
dependencies = [
|
||||
"derive_arbitrary",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arboard"
|
||||
version = "3.7.0"
|
||||
@@ -830,15 +839,6 @@ version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be95d4a884358a21a199689323c29e9256b4a1b315e22f183d155422041d3a9a"
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9eb6feb175df65d0a3ccd3e73484e940d0ac664e8034f0519fd49a93db3071d9"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.4"
|
||||
@@ -1150,7 +1150,7 @@ dependencies = [
|
||||
"verifysign",
|
||||
"winreg",
|
||||
"winsafe",
|
||||
"zip",
|
||||
"zip 9.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1253,7 +1253,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c85293
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
"zip",
|
||||
"zip 9.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1263,7 +1263,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd98301
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
"zip",
|
||||
"zip 9.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1391,6 +1391,17 @@ version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e"
|
||||
|
||||
[[package]]
|
||||
name = "derive_arbitrary"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b034bd7d5f032402a2479444dcc6f74e36a03f31854d41680fb240ef682a1ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dify"
|
||||
version = "0.8.0"
|
||||
@@ -2315,7 +2326,7 @@ dependencies = [
|
||||
"log",
|
||||
"quick-xml 0.41.0",
|
||||
"serde_json",
|
||||
"zip",
|
||||
"zip 3.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2352,7 +2363,7 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
"unicode-segmentation",
|
||||
"web-time",
|
||||
"zip",
|
||||
"zip 3.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2503,7 +2514,7 @@ dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"sha2 0.11.1",
|
||||
"thiserror 2.0.21",
|
||||
"zip",
|
||||
"zip 3.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7231,22 +7242,32 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "9.8.2"
|
||||
version = "3.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d8dbe089cf6b0448b78f5fc50139ab5aaa40d08ac07cdc1baf2c13add35fcce"
|
||||
checksum = "12598812502ed0105f607f941c386f43d441e00148fce9dec3ca5ffb0bde9308"
|
||||
dependencies = [
|
||||
"arbitrary",
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
"indexmap",
|
||||
"memchr",
|
||||
"zopfli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "9.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2886b00003a72c4ccee3f42cfc34908d33b2508a74d827dc2a4244706475c704"
|
||||
dependencies = [
|
||||
"constant_time_eq",
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
"getrandom 0.4.3",
|
||||
"indexmap",
|
||||
"libc",
|
||||
"memchr",
|
||||
"nix",
|
||||
"typed-path",
|
||||
"windows-sys 0.61.2",
|
||||
"zeroize",
|
||||
"zopfli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ web-time = "1.1.0"
|
||||
rayon = "1"
|
||||
regex = { version = "1", default-features = false, features = ["std", "unicode", "perf"] }
|
||||
quick-xml = "0.41"
|
||||
zip = { version = "9.8.2", default-features = false, features = ["deflate"] }
|
||||
zip = { version = "3", default-features = false, features = ["deflate"] }
|
||||
sha2 = { version = "0.11", default-features = false }
|
||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
|
||||
|
||||
|
||||
@@ -110,20 +110,12 @@ fn resolve_target(source_dir: &str, target: &str) -> String {
|
||||
|
||||
type Zip<'a> = zip::ZipArchive<Cursor<&'a [u8]>>;
|
||||
|
||||
/// `(index, name)` of every file entry. Parts are read by index: two entries can decode to the
|
||||
/// same name, and looking up a CP437 name scans the whole archive.
|
||||
fn zip_names(zip: &mut Zip<'_>) -> Vec<(usize, String)> {
|
||||
(0..zip.len().min(MAX_ENTRIES)).filter_map(|i| zip.by_index_raw(i).ok().filter(|f| !f.is_dir()).map(|f| (i, entry_name(&f)))).collect()
|
||||
fn zip_names(zip: &mut Zip<'_>) -> Vec<String> {
|
||||
(0..zip.len().min(MAX_ENTRIES)).filter_map(|i| zip.by_index_raw(i).ok().filter(|f| !f.is_dir()).map(|f| f.name().to_string())).collect()
|
||||
}
|
||||
|
||||
/// An entry's name: UTF-8, or CP437 when the entry isn't flagged UTF-8. A name that doesn't decode
|
||||
/// is listed with its raw bytes made lossy, so the entry is still checked and reported.
|
||||
fn entry_name<R: std::io::Read>(f: &zip::read::ZipFile<'_, R>) -> String {
|
||||
f.name().map(|n| n.into_owned()).unwrap_or_else(|_| String::from_utf8_lossy(f.name_raw()).into_owned())
|
||||
}
|
||||
|
||||
fn read_zip_part(zip: &mut Zip<'_>, index: usize, name: &str) -> Result<Vec<u8>, String> {
|
||||
let f = zip.by_index(index).map_err(|e| format!("{name}: {e}"))?;
|
||||
fn read_zip_part(zip: &mut Zip<'_>, name: &str) -> Result<Vec<u8>, String> {
|
||||
let f = zip.by_name(name).map_err(|e| format!("{name}: {e}"))?;
|
||||
let mut buf = Vec::new();
|
||||
f.take(MAX_XML_PART).read_to_end(&mut buf).map_err(|e| format!("{name}: {e}"))?;
|
||||
Ok(buf)
|
||||
@@ -136,8 +128,8 @@ enum PartError {
|
||||
}
|
||||
|
||||
/// Reads a part like [`read_zip_part`], charging the decompressed bytes to `budget`.
|
||||
fn read_zip_part_within(zip: &mut Zip<'_>, index: usize, budget: &mut u64) -> Result<Vec<u8>, PartError> {
|
||||
let f = zip.by_index(index).map_err(|_| PartError::Unreadable)?;
|
||||
fn read_zip_part_within(zip: &mut Zip<'_>, name: &str, budget: &mut u64) -> Result<Vec<u8>, PartError> {
|
||||
let f = zip.by_name(name).map_err(|_| PartError::Unreadable)?;
|
||||
// One byte past what is left shows that the part doesn't fit.
|
||||
let limit = MAX_XML_PART.min(budget.saturating_add(1));
|
||||
let mut buf = Vec::new();
|
||||
@@ -158,10 +150,10 @@ fn read_zip_part_within(zip: &mut Zip<'_>, index: usize, budget: &mut u64) -> Re
|
||||
pub(super) fn full_calc_on_load(bytes: &[u8]) -> bool {
|
||||
let Ok(mut zip) = zip::ZipArchive::new(Cursor::new(bytes)) else { return false };
|
||||
let names = zip_names(&mut zip);
|
||||
let find = |key: &str| names.iter().find(|(_, n)| part_key(n) == key).cloned();
|
||||
let find = |key: &str| names.iter().find(|n| part_key(n) == key).cloned();
|
||||
let mut workbook = "xl/workbook.xml".to_string();
|
||||
if let Some((i, rels)) = find("_rels/.rels")
|
||||
&& let Ok(xml) = read_zip_part(&mut zip, i, &rels)
|
||||
if let Some(rels) = find("_rels/.rels")
|
||||
&& let Ok(xml) = read_zip_part(&mut zip, &rels)
|
||||
&& let Ok(els) = xml_elements(&xml)
|
||||
&& let Some(target) = els
|
||||
.iter()
|
||||
@@ -170,8 +162,8 @@ pub(super) fn full_calc_on_load(bytes: &[u8]) -> bool {
|
||||
{
|
||||
workbook = resolve_target("", target);
|
||||
}
|
||||
let Some((i, name)) = find(&part_key(&workbook)) else { return false };
|
||||
let Ok(xml) = read_zip_part(&mut zip, i, &name) else { return false };
|
||||
let Some(name) = find(&part_key(&workbook)) else { return false };
|
||||
let Ok(xml) = read_zip_part(&mut zip, &name) else { return false };
|
||||
xml_elements(&xml)
|
||||
.ok()
|
||||
.into_iter()
|
||||
@@ -185,15 +177,15 @@ pub(super) fn full_calc_on_load(bytes: &[u8]) -> bool {
|
||||
pub fn validate_package(bytes: &[u8]) -> Result<Vec<String>, String> {
|
||||
let mut zip = zip::ZipArchive::new(Cursor::new(bytes)).map_err(|e| format!("not a zip package: {e}"))?;
|
||||
let names = zip_names(&mut zip);
|
||||
let parts: HashSet<String> = names.iter().map(|(_, n)| part_key(n)).collect();
|
||||
let mut read_part = |index: usize, name: &str| read_zip_part(&mut zip, index, name);
|
||||
let parts: HashSet<String> = names.iter().map(|n| part_key(n)).collect();
|
||||
let mut read_part = |name: &str| read_zip_part(&mut zip, name);
|
||||
let mut issues = Vec::new();
|
||||
let ct_name = names.iter().find(|(_, n)| part_key(n) == "[content_types].xml").cloned();
|
||||
let ct_name = names.iter().find(|n| part_key(n) == "[content_types].xml").cloned();
|
||||
let (mut defaults, mut overrides) = (HashSet::new(), HashSet::new());
|
||||
match ct_name {
|
||||
None => issues.push("no [Content_Types].xml".to_string()),
|
||||
Some((i, n)) => {
|
||||
for (el, attrs) in xml_elements(&read_part(i, &n)?).map_err(|e| format!("[Content_Types].xml: {e}"))? {
|
||||
Some(n) => {
|
||||
for (el, attrs) in xml_elements(&read_part(&n)?).map_err(|e| format!("[Content_Types].xml: {e}"))? {
|
||||
match el.as_str() {
|
||||
"Default" => {
|
||||
if let Some(x) = attr(&attrs, "Extension") {
|
||||
@@ -210,9 +202,9 @@ pub fn validate_package(bytes: &[u8]) -> Result<Vec<String>, String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut sorted: Vec<&(usize, String)> = names.iter().collect();
|
||||
sorted.sort_by(|a, b| a.1.cmp(&b.1).then(a.0.cmp(&b.0)));
|
||||
for (_, n) in &sorted {
|
||||
let mut sorted: Vec<&String> = names.iter().collect();
|
||||
sorted.sort();
|
||||
for n in &sorted {
|
||||
let key = part_key(n);
|
||||
if key == "[content_types].xml" {
|
||||
continue;
|
||||
@@ -227,7 +219,7 @@ pub fn validate_package(bytes: &[u8]) -> Result<Vec<String>, String> {
|
||||
for p in missing_overrides {
|
||||
issues.push(format!("content type override for missing part /{p}"));
|
||||
}
|
||||
for (i, n) in sorted {
|
||||
for n in sorted {
|
||||
let key = part_key(n);
|
||||
let Some(rels_file) = key.strip_suffix(".rels") else { continue };
|
||||
// `dir/_rels/name.rels` describes `dir/name`; `_rels/.rels` the package itself.
|
||||
@@ -241,7 +233,7 @@ pub fn validate_package(bytes: &[u8]) -> Result<Vec<String>, String> {
|
||||
issues.push(format!("{n} describes missing part {source}"));
|
||||
}
|
||||
let mut ids = HashSet::new();
|
||||
for (el, attrs) in xml_elements(&read_part(*i, n)?).map_err(|e| format!("{n}: {e}"))? {
|
||||
for (el, attrs) in xml_elements(&read_part(n)?).map_err(|e| format!("{n}: {e}"))? {
|
||||
if el != "Relationship" {
|
||||
continue;
|
||||
}
|
||||
@@ -276,17 +268,17 @@ pub(super) fn relationship_kinds(bytes: &[u8]) -> Result<BTreeMap<String, String
|
||||
fn relationship_kinds_within(bytes: &[u8], mut budget: u64) -> Result<BTreeMap<String, String>, String> {
|
||||
let mut zip = zip::ZipArchive::new(Cursor::new(bytes)).map_err(|e| format!("not a zip package: {e}"))?;
|
||||
let names = zip_names(&mut zip);
|
||||
let by_key: HashMap<String, &(usize, String)> = names.iter().map(|e| (part_key(&e.1), e)).collect();
|
||||
let by_key: HashMap<String, &String> = names.iter().map(|n| (part_key(n), n)).collect();
|
||||
// Several relationships name the same part; each fresh check decompressed it again, so
|
||||
// repeated references to one highly compressible part multiplied the work. The verdict is
|
||||
// remembered per (part, named content) and the decompression the package can cause is
|
||||
// budgeted as a whole, the relationship parts included: many large, unreferenced rels parts
|
||||
// would otherwise each spend a full per-part allowance.
|
||||
let mut verdicts: HashMap<(usize, &'static str), bool> = HashMap::new();
|
||||
let mut verdicts: HashMap<(String, &'static str), bool> = HashMap::new();
|
||||
let mut kinds = BTreeMap::new();
|
||||
for (i, n) in names.iter().filter(|(_, n)| part_key(n).ends_with(".rels")) {
|
||||
for n in names.iter().filter(|n| part_key(n).ends_with(".rels")) {
|
||||
let Some(src_dir) = rels_source_dir(&part_key(n)) else { continue };
|
||||
let xml = match read_zip_part_within(&mut zip, *i, &mut budget) {
|
||||
let xml = match read_zip_part_within(&mut zip, n, &mut budget) {
|
||||
Ok(xml) => xml,
|
||||
Err(PartError::OverBudget) => return Err(format!("{n}: relationship check stopped at its decompression limit")),
|
||||
Err(PartError::Unreadable) => continue,
|
||||
@@ -300,8 +292,8 @@ fn relationship_kinds_within(bytes: &[u8], mut budget: u64) -> Result<BTreeMap<S
|
||||
}
|
||||
let external = attr(attrs, "TargetMode").is_some_and(|m| m.eq_ignore_ascii_case("External"));
|
||||
if !external
|
||||
&& let Some((index, _)) = by_key.get(&resolve_target(&src_dir, target).to_ascii_lowercase())
|
||||
&& !holds_something(&mut zip, *index, kind, &mut verdicts, &mut budget)
|
||||
&& let Some(part) = by_key.get(&resolve_target(&src_dir, target).to_ascii_lowercase())
|
||||
&& !holds_something(&mut zip, part, kind, &mut verdicts, &mut budget)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -322,7 +314,7 @@ fn rels_source_dir(key: &str) -> Option<String> {
|
||||
/// comes first) a comment, for VML a shape. Read only as far as needed; an unreadable part counts.
|
||||
/// `verdicts` remembers the answer per (part, named content); `budget` is the decompression this
|
||||
/// package's remaining checks may cause, and once it is spent the part counts as having content.
|
||||
fn holds_something(zip: &mut Zip<'_>, index: usize, kind: &str, verdicts: &mut HashMap<(usize, &'static str), bool>, budget: &mut u64) -> bool {
|
||||
fn holds_something(zip: &mut Zip<'_>, name: &str, kind: &str, verdicts: &mut HashMap<(String, &'static str), bool>, budget: &mut u64) -> bool {
|
||||
let wanted: Option<&'static [u8]> = match kind.to_ascii_lowercase().as_str() {
|
||||
"comments" => Some(b"comment"),
|
||||
"vmldrawing" => Some(b"shape"),
|
||||
@@ -333,17 +325,17 @@ fn holds_something(zip: &mut Zip<'_>, index: usize, kind: &str, verdicts: &mut H
|
||||
Some(_) => "shape",
|
||||
None => "any",
|
||||
};
|
||||
if let Some(v) = verdicts.get(&(index, marker)) {
|
||||
if let Some(v) = verdicts.get(&(name.to_ascii_lowercase(), marker)) {
|
||||
return *v;
|
||||
}
|
||||
let v = holds_something_uncached(zip, index, marker, budget);
|
||||
verdicts.insert((index, marker), v);
|
||||
let v = holds_something_uncached(zip, name, marker, budget);
|
||||
verdicts.insert((name.to_ascii_lowercase(), marker), v);
|
||||
v
|
||||
}
|
||||
|
||||
fn holds_something_uncached(zip: &mut Zip<'_>, index: usize, marker: &'static str, budget: &mut u64) -> bool {
|
||||
fn holds_something_uncached(zip: &mut Zip<'_>, name: &str, marker: &'static str, budget: &mut u64) -> bool {
|
||||
use quick_xml::events::Event;
|
||||
let Ok(f) = zip.by_index(index) else { return true };
|
||||
let Ok(f) = zip.by_name(name) else { return true };
|
||||
if *budget == 0 {
|
||||
return true;
|
||||
}
|
||||
@@ -400,57 +392,6 @@ mod tests {
|
||||
z.finish().unwrap().into_inner()
|
||||
}
|
||||
|
||||
/// A package with two relationship parts whose names both read `xl/_rels/é.xml.rels`: the first
|
||||
/// stored as UTF-8 holding `first`, the second stored as CP437 (byte 0x82) holding `second`.
|
||||
fn same_name_rels(first: &str, second: &str) -> Vec<u8> {
|
||||
const PLACEHOLDER: &[u8] = b"xl/_rels/Q.xml.rels";
|
||||
let mut z = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
let opts = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated);
|
||||
z.start_file("xl/_rels/\u{e9}.xml.rels", opts).unwrap();
|
||||
z.write_all(first.as_bytes()).unwrap();
|
||||
z.start_file(String::from_utf8(PLACEHOLDER.to_vec()).unwrap(), opts).unwrap();
|
||||
z.write_all(second.as_bytes()).unwrap();
|
||||
let mut bytes = z.finish().unwrap().into_inner();
|
||||
// The name sits in the local header and in the central directory; both get the CP437 byte.
|
||||
let mut at = 0;
|
||||
let mut patched = 0;
|
||||
while let Some(i) = bytes.get(at..).and_then(|rest| rest.windows(PLACEHOLDER.len()).position(|w| w == PLACEHOLDER)) {
|
||||
bytes[at + i + 9] = 0x82;
|
||||
at += i + PLACEHOLDER.len();
|
||||
patched += 1;
|
||||
}
|
||||
assert_eq!(patched, 2);
|
||||
bytes
|
||||
}
|
||||
|
||||
fn rels_xml(rels: &[(&str, &str)]) -> String {
|
||||
let body: String = rels
|
||||
.iter()
|
||||
.map(|(id, kind)| {
|
||||
format!(
|
||||
r#"<Relationship Id="{id}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/{kind}" Target="https://example.com" TargetMode="External"/>"#
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
format!(r#"<?xml version="1.0"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">{body}</Relationships>"#)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parts_with_the_same_decoded_name_are_each_validated() {
|
||||
let bytes = same_name_rels(&rels_xml(&[("rId1", "custom")]), &rels_xml(&[("rId1", "custom"), ("rId1", "custom")]));
|
||||
let issues = validate_package(&bytes).unwrap();
|
||||
let duplicates = issues.iter().filter(|i| i.ends_with("duplicate relationship id rId1")).count();
|
||||
assert_eq!(duplicates, 1, "{issues:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relationship_kinds_read_parts_with_the_same_decoded_name() {
|
||||
let bytes = same_name_rels(&rels_xml(&[("rId1", "custom")]), &rels_xml(&[("rId1", "audio")]));
|
||||
let kinds = relationship_kinds(&bytes).unwrap();
|
||||
assert!(kinds.contains_key("custom"), "{kinds:?}");
|
||||
assert!(kinds.contains_key("audio"), "{kinds:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relationship_parts_count_against_the_decompression_budget() {
|
||||
// Each part fits the per-part allowance, but together they need more than the budget.
|
||||
|
||||
@@ -344,7 +344,7 @@ fn with_rels(bytes: &[u8], rels: &[(&str, &str)], parts: &[(&str, &str)]) -> Vec
|
||||
let mut pending: Vec<(&str, &str)> = rels.to_vec();
|
||||
for i in 0..src.len() {
|
||||
let mut f = src.by_index(i).unwrap();
|
||||
let name = f.name().unwrap().to_string();
|
||||
let name = f.name().to_string();
|
||||
let mut body = String::new();
|
||||
f.read_to_string(&mut body).unwrap();
|
||||
if let Some(at) = pending.iter().position(|(r, _)| *r == name) {
|
||||
|
||||
@@ -531,7 +531,7 @@ fn edit_parts(bytes: &[u8], mut edit: impl FnMut(&str, String) -> String) -> Vec
|
||||
let mut out = zip::ZipWriter::new(Cursor::new(Vec::new()));
|
||||
for i in 0..zip.len() {
|
||||
let mut part = zip.by_index(i).unwrap();
|
||||
let name = part.name().unwrap().to_string();
|
||||
let name = part.name().to_string();
|
||||
let mut data = Vec::new();
|
||||
part.read_to_end(&mut data).unwrap();
|
||||
let data = match String::from_utf8(data) {
|
||||
|
||||
@@ -56,7 +56,7 @@ fn with_parts(bytes: &[u8], edit: impl Fn(&str, &str) -> String, add: &[(&str, &
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let name = f.name().unwrap().to_string();
|
||||
let name = f.name().to_string();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).unwrap();
|
||||
if let Ok(text) = std::str::from_utf8(&data) {
|
||||
@@ -250,7 +250,7 @@ fn with_damaged_part(bytes: &[u8], name: &str, marker: &str) -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let entry = f.name().unwrap().to_string();
|
||||
let entry = f.name().to_string();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).unwrap();
|
||||
let options = zip::write::SimpleFileOptions::default();
|
||||
|
||||
@@ -60,7 +60,7 @@ fn edit_chart(bytes: &[u8], edit: impl Fn(String) -> String) -> Vec<u8> {
|
||||
let mut out = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for i in 0..z.len() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let name = f.name().unwrap().to_string();
|
||||
let name = f.name().to_string();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).unwrap();
|
||||
if name == "xl/charts/chart1.xml" {
|
||||
|
||||
@@ -42,7 +42,7 @@ fn unzip(bytes: &[u8]) -> BTreeMap<String, Vec<u8>> {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut b = Vec::new();
|
||||
f.read_to_end(&mut b).unwrap();
|
||||
m.insert(f.name().unwrap().to_string(), b);
|
||||
m.insert(f.name().to_string(), b);
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ fn drawing_with_picture_and_chart() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut d = vec![];
|
||||
std::io::Read::read_to_end(&mut f, &mut d).unwrap();
|
||||
parts.push((f.name().unwrap().to_string(), d));
|
||||
parts.push((f.name().to_string(), d));
|
||||
}
|
||||
parts.push(("xl/media/image1.png".into(), png.to_vec()));
|
||||
let refs: Vec<(&str, &[u8])> = parts.iter().map(|(n, d)| (n.as_str(), d.as_slice())).collect();
|
||||
|
||||
@@ -163,7 +163,7 @@ fn hostile_threaded_comments_persons_and_note_vml() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut d = vec![];
|
||||
std::io::Read::read_to_end(&mut f, &mut d).unwrap();
|
||||
parts.push((f.name().unwrap().to_string(), d));
|
||||
parts.push((f.name().to_string(), d));
|
||||
}
|
||||
let ns = r#"xmlns="http://schemas.microsoft.com/office/spreadsheetml/2018/threadedcomments""#;
|
||||
let deep = "<v:group>".repeat(300) + &"</v:group>".repeat(300);
|
||||
|
||||
@@ -26,7 +26,7 @@ fn package() -> Vec<u8> {
|
||||
/// The written VML part (GridCraft writes one per sheet with notes).
|
||||
fn written_vml(bytes: &[u8]) -> String {
|
||||
let mut z = zip::ZipArchive::new(std::io::Cursor::new(bytes)).unwrap();
|
||||
let name = (0..z.len()).map(|i| z.by_index(i).unwrap().name().unwrap().to_string()).find(|n| n.ends_with(".vml")).expect("a VML part");
|
||||
let name = (0..z.len()).map(|i| z.by_index(i).unwrap().name().to_string()).find(|n| n.ends_with(".vml")).expect("a VML part");
|
||||
let mut s = String::new();
|
||||
z.by_name(&name).unwrap().read_to_string(&mut s).unwrap();
|
||||
s
|
||||
|
||||
@@ -129,7 +129,7 @@ impl Unpacked {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut v = vec![];
|
||||
f.read_to_end(&mut v).unwrap();
|
||||
parts.insert(f.name().unwrap().to_string(), v);
|
||||
parts.insert(f.name().to_string(), v);
|
||||
}
|
||||
Unpacked { parts }
|
||||
}
|
||||
@@ -707,7 +707,7 @@ fn chart_sheet_entries_sharing_a_graph_are_checked_once() {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut data = Vec::new();
|
||||
f.read_to_end(&mut data).unwrap();
|
||||
parts.push((f.name().unwrap().to_string(), data));
|
||||
parts.push((f.name().to_string(), data));
|
||||
}
|
||||
let extra: String = (0..3_000).map(|i| format!(r#"<sheet name="Copy{i}" sheetId="{}" r:id="rId2"/>"#, 100 + i)).collect();
|
||||
for (name, data) in &mut parts {
|
||||
|
||||
@@ -210,7 +210,7 @@ fn unzip(bytes: &[u8]) -> HashMap<String, Vec<u8>> {
|
||||
let mut f = z.by_index(i).unwrap();
|
||||
let mut b = Vec::new();
|
||||
f.read_to_end(&mut b).unwrap();
|
||||
m.insert(f.name().unwrap().to_string(), b);
|
||||
m.insert(f.name().to_string(), b);
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
@@ -633,7 +633,7 @@ fn assert_drawing_and_chart_roundtrip(a: &Sheet, b: &Sheet) {
|
||||
fn package_structure() {
|
||||
let bytes = write_xlsx(&sample()).unwrap();
|
||||
let mut z = zip::ZipArchive::new(std::io::Cursor::new(bytes)).unwrap();
|
||||
let names: Vec<String> = (0..z.len()).map(|i| z.name_for_index(i).unwrap().unwrap().to_string()).collect();
|
||||
let names: Vec<String> = (0..z.len()).map(|i| z.name_for_index(i).unwrap().to_string()).collect();
|
||||
assert_eq!(names[0], "[Content_Types].xml");
|
||||
for n in [
|
||||
"_rels/.rels",
|
||||
@@ -900,7 +900,7 @@ fn vba_project_roundtrip() {
|
||||
assert_eq!(write_xlsx(&wb).unwrap(), bytes, "output is deterministic");
|
||||
|
||||
let mut z = zip::ZipArchive::new(std::io::Cursor::new(bytes.clone())).unwrap();
|
||||
let names: Vec<String> = (0..z.len()).map(|i| z.name_for_index(i).unwrap().unwrap().to_string()).collect();
|
||||
let names: Vec<String> = (0..z.len()).map(|i| z.name_for_index(i).unwrap().to_string()).collect();
|
||||
assert!(names.iter().any(|x| x == "xl/vbaProject.bin"), "missing vbaProject.bin");
|
||||
let mut bin = vec![];
|
||||
z.by_name("xl/vbaProject.bin").unwrap().read_to_end(&mut bin).unwrap();
|
||||
|
||||
@@ -25,7 +25,7 @@ fn sheet_with(name: &str, pictures: &[(u32, &[u8])]) -> Arc<Sheet> {
|
||||
|
||||
fn names(bytes: &[u8]) -> Vec<String> {
|
||||
let z = zip::ZipArchive::new(std::io::Cursor::new(bytes.to_vec())).unwrap();
|
||||
z.file_names().map(|n| n.unwrap().into_owned()).collect()
|
||||
z.file_names().map(str::to_string).collect()
|
||||
}
|
||||
|
||||
fn text(bytes: &[u8], name: &str) -> String {
|
||||
|
||||
@@ -108,7 +108,7 @@ fn every_trendline_kind_round_trips_in_every_chart_group() {
|
||||
fn chart_parts(bytes: &[u8]) -> Vec<String> {
|
||||
let mut z = zip::ZipArchive::new(std::io::Cursor::new(bytes.to_vec())).unwrap();
|
||||
let mut names: Vec<String> =
|
||||
(0..z.len()).map(|i| z.name_for_index(i).unwrap().unwrap().to_string()).filter(|n| n.starts_with("xl/charts/chart")).collect();
|
||||
(0..z.len()).map(|i| z.name_for_index(i).unwrap().to_string()).filter(|n| n.starts_with("xl/charts/chart")).collect();
|
||||
names.sort();
|
||||
names
|
||||
.iter()
|
||||
|
||||
@@ -17,7 +17,7 @@ fn package_starts_with_content_types_rels_and_workbook_before_any_large_part() {
|
||||
let bytes = write_xlsx(&wb).unwrap();
|
||||
|
||||
let mut zip = zip::ZipArchive::new(std::io::Cursor::new(&bytes)).unwrap();
|
||||
let names: Vec<String> = (0..zip.len()).filter_map(|i| zip.by_index(i).ok().map(|f| f.name().unwrap().to_string())).collect();
|
||||
let names: Vec<String> = (0..zip.len()).filter_map(|i| zip.by_index(i).ok().map(|f| f.name().to_string())).collect();
|
||||
assert_eq!(names.first().map(String::as_str), Some("[Content_Types].xml"), "{names:?}");
|
||||
assert_eq!(names.get(1).map(String::as_str), Some("_rels/.rels"), "{names:?}");
|
||||
assert_eq!(names.get(2).map(String::as_str), Some("xl/_rels/workbook.xml.rels"), "{names:?}");
|
||||
|
||||
Reference in New Issue
Block a user