* settings, atomic: give a replaced file's group bits only to its group
write_backup copied the config's mode onto a new backup inode without
giving it the config's group, and craft-atomic's stage() did the same
for every replaced file: on a setgid directory or with another primary
group, the group bits opened the contents to a group never granted
them. Both now chown the new inode to the replaced file's group first
and drop the group bits when that fails.
* address review: skip fchown when the stage already has the replaced file's group
* atomic: route the stage's group change through AtomicFs so the fallback is tested
* tiff: share WordCraft classic compression probe
Extracted from storytold/wordcraft crates/geom/src/picture.rs at fe8a8a838cde68b272ac68429e53049347feab40. Original implementation by VoiceLessQ; retains Dylan Taylor duplicate-tag hardening from ab0020d6f.
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
* tiff: cover compression probe refusal and endian parity
* test(tiff): allow assertions on bounded fixture conversions
---------
Co-authored-by: VoiceLessQ <t12kaem@gmail.com>
Moves the header pieces of Craft Anything's crates/formats/src/elf.rs
into a pure-Rust crate: the class/endian-aware reader, program_headers,
ProgramHeader, dynamic_entries, va_to_off, and the segment type,
permission and dynamic tag names. Mitigations, dynamic symbols, symbol
versions and core-file notes stay in the app.
Part of #778.
Co-authored-by: BFlat <bombayapirat@gmail.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
Co-authored-by: GGWA <65288322+rech4210@users.noreply.github.com>
* craft-docx: write Word 2010 shapes inside mc:AlternateContent with a VML fallback
A shape was written as a bare `wps:wsp` in `w:drawing`. Word 2007, and
Word 2000-2003 with the Office Compatibility Pack, don't know `wps` and
refuse the whole file. Word writes such shapes in `mc:AlternateContent`.
`write_shape` now guards the drawing with `mc:Choice Requires="wps"` and,
for rectangles, text boxes, rounded rectangles and ellipses, adds an
`mc:Fallback` with the shape as VML: size, position, z-order, wrapping,
fill, outline and the text box's text (copied from the choice's output,
so the story isn't written twice). Other kinds get no fallback; an old
reader skips that shape and still opens the file.
Refs storytold/wordcraft#6849
* craft-docx: guard a shape only when it gets a VML fallback; keep more in the fallback
A shape guarded by `mc:AlternateContent` with no fallback is skipped by
a reader that doesn't know `wps`, and dropped on that reader's next save:
worse than refusing the file. Such shapes are written bare again; only
shapes with a VML form are guarded.
The VML fallback also keeps the shape's own stacking order (a floating
object in its text box moved `self.z` on), its wrap distances, its hidden
flag and its text box's text direction.
* craft-docx: keep behind-text shapes' order in the VML fallback
A behind-text shape's fallback `z-index` was the negated `z`, which
reverses the order of overlapping behind-text shapes. It is now `z`
shifted below zero within signed 32-bit range, so a higher `z` still
stacks higher; other shapes' `z-index` is capped at `i32::MAX`.
* fix(docx): preserve linked text boxes without an incomplete VML fallback
---------
Co-authored-by: Andy Ching <53651198+andyching168@users.noreply.github.com>
* image-codecs: read a raster's resolution from its headers (resolution_probe)
file_resolution(bytes) gives the pixels per inch a JPEG, PNG, WebP, BMP or
classic TIFF records without decoding pixels. JPEG uses the decoder's marker
scan (Photoshop, XMP, EXIF, then JFIF), PNG reads pHYs as the decoder does and
falls back to eXIf, WebP its EXIF chunk, TIFF its IFD0 tags; BMP reads the
info header's pixels per metre. Values outside 1-100000 ppi count as none.
DesignCraft (crates/images/src/resolution.rs) and FigCraft
(crates/format/src/density.rs) each carry their own marker and chunk walkers
for this; they can switch to the shared probe.
Part of #778 and #785.
* image-codecs: resolution_probe reads only a whole nine-byte pHYs, and a zero one leaves eXIf
A pHYs chunk that declares any other length, or is cut off before its
CRC, records nothing, and its data is no longer read from the bytes
after it. A zero pixels-per-metre count records nothing either, as in the
decoder, so the eXIf resolution still answers.
tree::primitive::recognize (and Path::primitive) returns the axis-aligned
basic shape a path draws: one closed contour whose points all lie on a
(rounded) rectangle's or ellipse's outline and that encloses its area. usvg
turns rect, circle and ellipse into paths; apps that edit them as shapes get
them back from the segments.
#778, #789. Comments and CDATA are skipped, and a declaration name is
only scanned up to MAX_NAME+1, so a comment full of `<!ENTITYx` markers
is no longer a quadratic walk. Names longer than MAX_NAME are still
recorded so the expansion guard can refuse them. Closepath also clears
the smooth-control history, so S and T after Z start from the current
point rather than reflecting the pre-close control.
* EXR: decode a flat part of a file that also holds deep parts
decode_part refused every part of a file with any deep part, and
decode_display_part, which checked only the selected part, still failed
because the exr crate's image reader validates every header and refuses
deep ones before it reads a chunk.
Both now decide from the selected part's own header. When any part is
deep, the selected flat part is read chunk by chunk: the flat headers are
validated, every part's offset table is walked from the end of the
headers, and only the selected table's chunks are read. A chunk must start
past the last offset table and inside the file, carry the selected part's
number and hold a block no other chunk of the part holds; anything else is
Malformed. Files with only flat parts keep the crate's reader.
The file-size ratio check, which was skipped for every part when any part
was deep, now applies to the flat parts of such a file; deep parts are not
counted.
* EXR: a flat part beside a deep part needs a chunk for each of its blocks
The chunk reader for a flat part of a file that also holds deep parts
refused only a second chunk for the same block. A tiled part's chunk that
named a level the part does not have was skipped without decompressing,
so the tile it took the place of had no chunk and the part decoded with
that tile left at zero.
Each chunk now has to hold one of the part's own blocks, taken from the
header, that no other chunk holds; anything else is Malformed. Since a
part has as many chunks as blocks, every block then has a chunk.
The mixed-file tests also run with a tiled flat part, and a new test
names a missing level and a repeated tile.
* EXR: a scan-line chunk beside a deep part must start at its block's first line
The block index of a scan-line chunk is its y offset divided by the
lines a block holds, rounded toward zero. A chunk whose y was not the
first line of a block, or lay up to 15 lines above the data window of
a ZIP part, still named a block and was decoded into it. Such a chunk
is now Malformed.
* EXR: a block too large to address is LimitExceeded instead of a panic
The exr crate bounds a flat chunk by a block's pixels times the bytes a
pixel takes, an unchecked product, before it reads the chunk. A 1 x 1
part with five float channels in 10^9 x 10^9 tiles passed every size
limit, and decode_part and decode_display_part then panicked with an
overflow, for files of flat parts only and for mixed files alike.
read_meta now computes the product with checked arithmetic for each
flat part and returns LimitExceeded when it does not fit in a usize.
* EXR: a chunk beside a deep part must fit the rest of the file
The exr crate allocates a chunk's declared payload, up to the size of a
block, before it reads it. In a mixed file whose flat part has large
tiles, a chunk declaring i32::MAX bytes made a 2 GiB allocation from a
file of a few hundred bytes. read_flat_part_chunks now reads the
declared length first and returns Malformed when it is longer than the
bytes left in the file.
* test(exr): verify mixed-part ratio and display block budgets
* fix(exr): bound mixed-part payload and block bookkeeping allocations
* fix(exr): expose internal ordinal helpers to regression tests
---------
Co-authored-by: dotCooCoo <RobertLeeLW@gmail.com>
Adds the content feature and cos::content: PDFCraft's crates/content, moved
here so other apps can read and write page content streams. The parser keeps
operator spans, skips and counts unreadable bytes, and keeps inline images
whole; tests move with it.
Refs #778
* ps: add a write feature for PostScript tokens
Numbers, strings, matrices, path data and Flate, so apps can emit a
PostScript or EPS program without owning the token serializer. Path and
paint operators can use the Language Reference names or the one-letter
names a bound prolog defines. Container concerns stay in craft-eps.
Part of #778 and #790.
* ps: tighten write-feature number trimming and Flate bounds
- Require flate2 1.1.10 so inflate rejects an incomplete zlib stream.
- Trim trailing zeros only when the token has a decimal point, so
places=0 keeps integer zeros at the 1e15 boundary.
- Use saturating_add when bounding inflate, so max = u64::MAX does not
overflow.
mjpeg::Decoder called craft_jpeg::decode with no Adobe transform, so a
packet with numeric component ids and APP14 transform 0 (RGB as stored)
was converted as YCbCr and came out in the wrong colours. The decoder
now reads the transform with craft_jpeg::adobe_transform, as the JPEG
image readers do. A regression test injects APP14 transforms 0 and 1;
it fails without the fix.
* svg: let SvgWriter name the encoding and write a DOCTYPE subset
VectorCraft's SVG document wrapper needs a Latin-1 declaration and a
<!DOCTYPE svg [ <!ENTITY …> ]> internal subset, including a minified
form with no extra newlines. The existing declaration was UTF-8 only,
and craft-xml's doctype helper writes only <!DOCTYPE name>.
Part of #778 and #789.
* svg: expose SvgWriter::as_str for a second pass on open markup
A consumer that rewrites character references or hashes the document
around a metadata element needs the text of an unclosed root. finish()
would close it first.
The geometry reader (craft_svg::paths) is the only part of the crate that
needs vectorcraft-geom and vectorcraft-pathops, and the tree is the only part
that needs craft-image-codecs. Both are now optional: paths is a default
feature and tree turns it on, so existing users build the same crate, while
an app that only needs SVG text, guards, path data, colours and the writer can
turn default features off and take no app crates or image codecs.
parse_color_alpha is parse_color keeping the alpha of #rgba, #rrggbbaa and
the fourth value of rgb()/hsl(). parse_color now calls it and still drops it.
Refs #778, #789
craft-unzip's raw-bytes reader moves unchanged into craft-zip as the
`lenient` module, behind the `lenient` feature (DEFLATE) and
`lenient-bzip2`, `lenient-lzma` and `lenient-zstd` for the other
methods, with `serde` for the listing types. craft-zip's default build
is unchanged; the module doesn't use the `zip` crate. Its unit and
integration tests move with it and run in craft-zip's test build.
* feat: add craft-mcp-server (JSON-RPC 2.0 MCP protocol)
Port from solidcraft: MCP server machinery any app may share,
independent of transport and tools.
- JSON-RPC 2.0 over stdio (newline-delimited)
- MCP lifecycle: initialize, initialized, ping, notifications
- Tools: register, list, call with schema validation
- Resources: register, list, get by URI or template
- Prompts: register, list, get with argument completion
- Content blocks: text, image (base64), progress tokens
No external dependencies beyond serde_json.
Follows craft-libs safety pattern: #![deny(clippy::unwrap_used, ...)]
* retrigger CI
* retrigger CI
* Record MCP server dependencies in workspace lockfile
* chore: update rustls-webpki 0.103.15→0.103.16 and zip 9.1.0→9.1.3
Moves the header half of Craft Anything's crates/formats/src/pe.rs into
a pure-Rust crate: PeHeaders/PeSection, headers, has_pe_header,
subsystem_name, rich_header, the data-directory names and the RVA
mapping helpers. The import, export, resource and program-model code
stays in the app for now.
Part of #778.
Co-authored-by: Afloat <ShuffleMonkey@163.com>
Co-authored-by: BFlat <bombayapirat@gmail.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
Moves Craft Anything's crates/formats/src/tarcpio.rs (main 090188d7) into a shared crate with
its unit tests, the TAR integration tests from crates/formats/tests, and the archive builders
those tests use. The public API is unchanged; CpioChecksum and cpio_with_checksum become public
so the app's firmware scanner can keep sharing its checksum allowance. The pax record handling
is split out of the walker (same checks, same warnings) to stay under the workspace's
cognitive-complexity limit. Serialize is behind an optional `serde` feature.
Co-authored-by: Brandon Thomas <echelon@gmail.com>
Co-authored-by: Afloat <ShuffleMonkey@163.com>
Co-authored-by: BFlat <bombayapirat@gmail.com>
Co-authored-by: RRFZ <247457381+Plastic-time@users.noreply.github.com>
Co-authored-by: NetterSilver <133535268+Silvertree2010@users.noreply.github.com>