Skip to content

Reject png/jpeg targets in file.save instead of writing zip bytes - #1698

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h5754-file-save-to-a-png-jpg-path-writ
Nov 3, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h5754-file-save-to-a-png-jpg-path-writ

Conversation

@Silvertree2010

@Silvertree2010 Silvertree2010 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Found while testing crates/engine/src/cmd/file.rs:489 (save, with save_bytes at :341-349 and format_for_path at :440) (no existing issue): file.save to a .png/.jpg path writes native deckcraft zip bytes under an image name and marks the deck saved.

Cause

format_for_path maps .png/.jpg/.jpeg to "png"/"jpeg", but save_bytes has no writer for them and falls through to the native .deckcraft zip. file.save then wrote that zip under an image name and marked the deck saved with the image path.

Fix

save_bytes now returns an error for the "png" and "jpeg" formats, so file.save and file.saveAs fail before anything is written or the deck is marked saved. The error points to file.export for image output.

Verified

  • Regression test tests::save_to_image_path_is_an_error_not_zip_bytes: fails on main without the fix and passes with it (cargo test -p deckcraft-engine save_to_image_path).
  • cargo xtask ci passes except backstage::tests::start_screen_opens_the_palette_and_preferences, which also fails on main without this change.

Not changed

Saving to other extensions with no writer, such as .odp, still falls back to native bytes. Image export (file.export and the UI's image exporter) is unchanged.

🤖 Generated with AI by ApolloOffice, see the Co-Authored-By trailers for the models

Summary by CodeRabbit

  • Bug Fixes
    • Saving a presentation directly as PNG or JPEG now returns an error instead of creating a file. The document path remains unchanged when the save fails.
    • To create a single-image presentation, use the export option.

Found while testing crates/engine/src/cmd/file.rs:489 (save, with save_bytes at :341-349 and format_for_path at :440)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

save_bytes now rejects PNG and JPEG formats. Regression coverage checks that the affected save commands return errors, create no file, and leave the document path unchanged.

Changes: Image save rejection

Layer / File(s) Summary
Reject image saves and verify state
crates/engine/src/cmd/file.rs, crates/engine/src/tests.rs
save_bytes rejects PNG and JPEG formats instead of using the native DeckCraft serializer. The regression test checks .png, .jpeg, and .jpg save requests for errors, no file creation, and an unchanged document path.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: nikitkara, echelon

Merge Risk: Minimal · up to 58c24

This change makes saving to a PNG or JPEG path fail with a message pointing to file.export, instead of writing ZIP bytes under an image name. The one remaining edge case needs an explicit format override that the user chose deliberately. No merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: rejecting PNG and JPEG targets in file.save instead of writing ZIP bytes.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1
crates/engine/src/cmd/file.rs-348-348: 1

348-348: Major · Data Integrity & Integration · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Reject image paths, not only image formats.

If file.save or file.saveAs receives {"path":"a.png","format":"deckcraft"}, this branch is bypassed. The _ arm writes native DeckCraft ZIP bytes to a.png, then mark_saved updates the document state. file.save explicitly accepts a format parameter, and the save flow applies it before writing. (raw.githubusercontent.com)

Reject .png, .jpg, and .jpeg paths before applying an explicit format. Add a regression case with "format": "deckcraft".

Proposed fix
-    let format = str_param(p, "format").unwrap_or(format_for_path(&path));
+    let path_format = format_for_path(&path);
+    if matches!(path_format, "png" | "jpeg") {
+        return Err(EngineError::Other(
+            "saving a presentation as a single image isn't supported; use file.export".into(),
+        ));
+    }
+    let format = str_param(p, "format").unwrap_or(path_format);

Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f68150e and 58c2488.

Files selected for processing: 2
  • crates/engine/src/cmd/file.rs
  • crates/engine/src/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 58c2488 into storytold:main Nov 3, 2026
7 checks passed
h-a-n-a-s-h-i pushed a commit that referenced this pull request Nov 3, 2026
Reject png/jpeg targets in file.save instead of writing zip bytes

# Conflicts:
#	crates/engine/src/tests.rs
@echelon

echelon commented Nov 3, 2026

Copy link
Copy Markdown
Member

One small change on top before landing: an explicit format: "jpg" is refused too, not only png and jpeg.

@echelon

echelon commented Nov 3, 2026

Copy link
Copy Markdown
Member

Landed on main, thank you @Silvertree2010 for the contribution! If you haven't already, come join us on Discord: https://discord.gg/artcraft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants