Skip to content

[BUG] Source-view inspection of a large Unicode DOCX panics when truncating extracted text #125

Closed

Description

@DWAA1660

Environment

Windows, Rust 1.99.1, NoteCraft 0.0.9 at 33429876e885613f6ff8f29a762b15b2be736401 (current main when tested). Verified against the real workspace libraries / front end with synthetic files and an isolated profile. No product source changes or mocks.

Reproduction

  1. Create a DOCX whose word/document.xml contains one paragraph with "a".repeat(262143) + "é" as its text.
  2. Attach the DOCX to a page.
  3. Open Page source and select the DOCX in the file list.

The synthetic package used for verification includes [Content_Types].xml, _rels/.rels and word/document.xml. There is no personal document content. A minimal XML body is:

let text = "a".repeat(262143) + "é";
let xml = format!(
  "<w:document xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:body><w:p><w:r><w:t>{text}</w:t></w:r></w:p></w:body></w:document>"
);
// Store xml as word/document.xml in a DOCX ZIP.

Actual result

Selecting the file through the actual codeview::show Office branch exits with:

panicked at crates/ui-egui/src/codeview.rs:436:18:
assertion failed: self.is_char_boundary(new_len)

The byte limit 262,144 falls inside the two-byte é at 262,143..262,145.

Expected result

Show a safely shortened text preview with an explicit truncation notice. Never panic on ordinary Unicode Office text. Use a valid character boundary when applying a byte cap; retain bounded reading too.

Cause / coverage

codeview.rs, office_text, calls text.truncate(MAX_SHOWN) without checking a UTF-8 boundary. DOCX/XLSX/PPTX text share this extraction path. Add a source-view regression where a multibyte character crosses the preview cap.

This is separate from #102's link resolver and from destructive editing of a truncated page: this DOCX path is read-only but still crashes.

Duplicate check

Checked all open/closed issues and PRs, including the first audit's #102-#116 and new PRs #117-#120. No existing issue or PR covering this specific behavior was found.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions