Repository navigation
feat(editor): preview Word, PowerPoint and Excel files - #29678
nebourocket wants to merge 1 commit into
Conversation
Open .docx, .pptx and .xlsx files as read-only previews in editor tabs, next to the existing image and PDF previews. - One shared Office MIME table feeds the local IPC, runtime/SSH and renderer paged-read routes so every route previews the same files. - docx-preview, @aiden0z/pptx-renderer and read-excel-file are lazy-loaded in their own chunks; sheets reuse the CSV grid. - Zips whose central directory declares more than 256 MB, document links, and chat image access are guarded.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
banco una banda |
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
04a4ee7c-3df9-42ca-865a-128fa252650f
⛔ Files ignored due to path filters: 4
pnpm-lock.yamlis excluded by!**/pnpm-lock.yamltests/e2e/fixtures/office/deck.pptxis excluded by!**/*.pptxtests/e2e/fixtures/office/engines.xlsxis excluded by!**/*.xlsxtests/e2e/fixtures/office/report.docxis excluded by!**/*.docx
📒 Files selected for processing: 22
package.jsonsrc/main/ipc/filesystem/filesystem-file-content-inspection.tssrc/main/ipc/filesystem/local-regular-file-read.test.tssrc/main/ipc/local-file-access-resolution.test.tssrc/main/ipc/local-file-access-resolution.tssrc/main/runtime/files/file-preview-budget.tssrc/renderer/src/components/editor/ImageViewer.tsxsrc/renderer/src/components/editor/office/DocxDocumentView.tsxsrc/renderer/src/components/editor/office/OfficeDocumentViewer.tsxsrc/renderer/src/components/editor/office/PptxDocumentView.tsxsrc/renderer/src/components/editor/office/XlsxDocumentView.tsxsrc/renderer/src/components/editor/office/office-document-bytes.tssrc/renderer/src/components/editor/office/office-document-links.tssrc/renderer/src/components/editor/office/office-zip-budget.test.tssrc/renderer/src/components/editor/office/office-zip-budget.tssrc/renderer/src/components/editor/office/xlsx-sheet-grid.test.tssrc/renderer/src/components/editor/office/xlsx-sheet-grid.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/runtime/runtime-paged-file-read.test.tssrc/renderer/src/runtime/runtime-paged-file-read.tssrc/shared/office-document-mime-types.tstests/e2e/office-document-preview.spec.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| const href = anchor.getAttribute('href') ?? '' | ||
| if (href.startsWith('#')) { | ||
| // Why: a native hash jump would change Orca's own location, so scroll to the bookmark instead. | ||
| const id = decodeURIComponent(href.slice(1)) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Catch URIError from decodeURIComponent.
decodeURIComponent throws a URIError for malformed input such as #%E0. Document authors control these hrefs. The error escapes the click handler and the bookmark jump does nothing. Fall back to the raw value when decoding fails.
Proposed fix
--- "a/src/renderer/src/components/editor/office/office-document-links.ts"
+++ "b/src/renderer/src/components/editor/office/office-document-links.ts"
@@ -17,7 +17,12 @@
const href = anchor.getAttribute('href') ?? ''
if (href.startsWith('#')) {
// Why: a native hash jump would change Orca's own location, so scroll to the bookmark instead.
- const id = decodeURIComponent(href.slice(1))
+ let id = href.slice(1)
+ try {
+ id = decodeURIComponent(id)
+ } catch {
+ // keep raw fragment
+ }
const target = [...container.querySelectorAll('[id],[name]')].find(
(element) => element.id === id || element.getAttribute('name') === id
)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const id = decodeURIComponent(href.slice(1)) | |
| let id = href.slice(1) | |
| try { | |
| id = decodeURIComponent(id) | |
| } catch { | |
| // keep raw fragment | |
| } |
| const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength) | ||
| const end = findEndOfCentralDirectory(view) | ||
| if (end === null) { | ||
| return false | ||
| } | ||
| const entryCount = view.getUint16(end + 10, true) | ||
| let offset = view.getUint32(end + 16, true) |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
set -eu
printf '%s\n' '--- helper ---'
nl -ba src/renderer/src/components/editor/office/office-zip-budget.ts
printf '%s\n' '--- references ---'
rg -n -F --glob '*.{ts,tsx,js,json}' -e 'officeZipWithinBudget' -e 'docx-preview' -e 'read-excel-file' -e 'zip' src package.json pnpm-lock.yaml 2>/dev/null || true
printf '%s\n' '--- package declarations ---'
rg -n -F --glob 'package.json' -e 'docx-preview' -e 'read-excel-file' -e 'fflate' -e 'jszip' -e 'unzip' .
printf '%s\n' '--- installed package sources ---'
if [ -d node_modules ]; then
find node_modules -maxdepth 4 \( -path '*docx-preview*' -o -path '*read-excel-file*' -o -path '*fflate*' -o -path '*jszip*' \) -type f | sed -n '1,200p'
else
printf '%s\n' 'node_modules unavailable'
fiRepository: stablyai/orca
Length of output: 32373
🏁 Script executed:
set -eu
printf '%s\n' '--- OfficeDocumentViewer ---'
nl -ba src/renderer/src/components/editor/office/OfficeDocumentViewer.tsx
printf '%s\n' '--- DocxDocumentView ---'
nl -ba src/renderer/src/components/editor/office/DocxDocumentView.tsx
printf '%s\n' '--- XlsxDocumentView ---'
nl -ba src/renderer/src/components/editor/office/XlsxDocumentView.tsx
printf '%s\n' '--- PptxDocumentView ---'
nl -ba src/renderer/src/components/editor/office/PptxDocumentView.tsx
printf '%s\n' '--- related tests ---'
nl -ba src/renderer/src/components/editor/office/office-zip-budget.test.ts
printf '%s\n' '--- lockfile package records ---'
sed -n '4800,4825p;6910,6940p;5720,5740p' pnpm-lock.yamlRepository: stablyai/orca
Length of output: 18867
🌐 Web query:
docx-preview 0.4.1 read-excel-file 9.3.12 ZIP inflation local header central directory source
💡 Result:
**Short answer:** they use different ZIP layers, and only `read-excel-file`’s package documentation explicitly identifies its decompression libraries.
- **`[email protected]`:** The package README says browser ZIP decompression uses **`fflate`**, while Node.js uses **`unzipper-esm`**. That establishes the libraries, but not their exact local-header/central-directory parsing path. ([npmjs.com](https://www.npmjs.com/package/read-excel-file?activeTab=readme&utm_source=openai))
- **`[email protected]`:** Its source repository is `VolodymyrBaydalka/docxjs`; the available source view shows ZIP access through a `JSZip` object (`this._zip.files` / `this._zip.file(...)`). This supports that the package delegates ZIP handling to JSZip, rather than implementing ZIP parsing itself. The fetched source is `master`, however—not a version-pinned 0.4.1 source file—so the exact 0.4.1 implementation remains unverified. ([github.com](https://github.com/VolodymyrBaydalka/docxjs/blob/master/dist/docx-preview.mjs?utm_source=openai))
For the specific mechanics: `fflate`’s source includes code to skip local headers and read ZIP headers; that illustrates its parser implementation, but the source retrieved is `master`, not a version-pinned dependency used by `[email protected]`. ([github.com](https://github.com/101arrowz/fflate/blob/master/src/index.ts?utm_source=openai))
**Bottom line:** the evidence points to **JSZip** for `docx-preview` and **fflate (browser) / unzipper-esm (Node)** for `read-excel-file`. I can’t confirm from the retrieved version-pinned sources exactly how either handles inflation and central-directory versus local-header fields in those precise releases.
Citations:
- 1: https://www.npmjs.com/package/read-excel-file?activeTab=readme&utm_source=openai
- 2: https://github.com/VolodymyrBaydalka/docxjs/blob/master/dist/docx-preview.mjs?utm_source=openai
- 3: https://github.com/101arrowz/fflate/blob/master/src/index.ts?utm_source=openai
🏁 Script executed:
python3 - <<'PY'
import io, re, tarfile, urllib.request
packages = [
('docx-preview', '0.4.1'),
('read-excel-file', '9.3.12'),
('jszip', '3.10.2'),
('fflate', '0.8.3'),
('unzipper-esm', '0.13.3'),
]
patterns = re.compile(
r'local|central|uncompressed|compressedSize|compressedSize|inflate|decompress|readData|file\.'
, re.I
)
for name, version in packages:
url = f'https://registry.npmjs.org/{name}/-/{name}-{version}.tgz'
print(f'--- {name}@{version} ---')
try:
data = urllib.request.urlopen(url, timeout=20).read()
tf = tarfile.open(fileobj=io.BytesIO(data), mode='r:gz')
shown = 0
for member in tf.getmembers():
if not member.isfile():
continue
text = tf.extractfile(member).read().decode('utf-8', 'replace')
lines = text.splitlines()
matches = [i for i, line in enumerate(lines) if patterns.search(line)]
if not matches:
continue
print(f'FILE {member.name}')
selected = []
for i in matches:
selected.extend(range(max(0, i - 2), min(len(lines), i + 3)))
for i in sorted(set(selected)):
print(f'{i + 1}:{lines[i]}')
shown += 1
if shown >= 12:
break
if shown == 0:
print('no matching source excerpts')
except Exception as exc:
print(type(exc).__name__ + ': ' + str(exc))
PY
printf '%s\n' '--- read-excel-file dependency records ---'
rg -n -A12 -B3 -F '[email protected]' pnpm-lock.yaml
printf '%s\n' '--- browser dependency records ---'
rg -n -A8 -B3 -F 'fflate@' pnpm-lock.yamlRepository: stablyai/orca
Length of output: 45667
🏁 Script executed:
python3 - <<'PY'
import io, re, tarfile, urllib.request
targets = [
('docx-preview', '0.4.1'),
('jszip', '3.10.2'),
('read-excel-file', '9.3.12'),
('fflate', '0.8.3'),
('unzipper-esm', '0.13.3'),
]
name_re = re.compile(r'(zip|unzip|inflate|decompress|xlsx)', re.I)
line_re = re.compile(
r'(compressedSize|uncompressedSize|compressed size|uncompressed size|'
r'local file|local header|central directory|inflateRaw|inflateSync|'
r'unzipSync|decompressSync|readData|entry\.size|vars\.size)',
re.I,
)
for name, version in targets:
url = f'https://registry.npmjs.org/{name}/-/{name}-{version}.tgz'
print(f'--- {name}@{version} ---')
data = urllib.request.urlopen(url, timeout=20).read()
tf = tarfile.open(fileobj=io.BytesIO(data), mode='r:gz')
candidates = [
m for m in tf.getmembers()
if m.isfile()
and name_re.search(m.name)
and not m.name.endswith(('.map', '.min.js'))
]
print('candidate files:', ', '.join(m.name for m in candidates[:40]))
for member in candidates:
text = tf.extractfile(member).read().decode('utf-8', 'replace')
lines = text.splitlines()
hits = [i for i, line in enumerate(lines) if line_re.search(line)]
if not hits:
continue
print(f'FILE {member.name}')
selected = set()
for i in hits:
selected.update(range(max(0, i - 2), min(len(lines), i + 3)))
for i in sorted(selected):
print(f'{i + 1}:{lines[i]}')
PYRepository: stablyai/orca
Length of output: 32916
🏁 Script executed:
python3 - <<'PY'
import io, re, tarfile, urllib.request
def package(name, version):
url = f'https://registry.npmjs.org/{name}/-/{name}-{version}.tgz'
return tarfile.open(fileobj=io.BytesIO(urllib.request.urlopen(url, timeout=20).read()), mode='r:gz')
print('--- fflate files ---')
tf = package('fflate', '0.8.3')
for m in tf.getmembers():
if m.isfile():
print(m.name)
print('--- fflate unzip/inflate excerpts ---')
for m in tf.getmembers():
if not m.isfile() or m.name.endswith('.map'):
continue
text = tf.extractfile(m).read().decode('utf-8', 'replace')
lines = text.splitlines()
hits = [
i for i, line in enumerate(lines)
if re.search(r'(unzipSync|function unzip|inflateSync|function inflate|csize|usize|uncompressed|compressed)', line, re.I)
]
if not hits:
continue
print(f'FILE {m.name}')
selected = set()
for i in hits:
selected.update(range(max(0, i - 2), min(len(lines), i + 3)))
for i in sorted(selected):
print(f'{i + 1}:{lines[i]}')
print('--- read-excel-file browser zip wrapper ---')
tf = package('read-excel-file', '9.3.12')
for m in tf.getmembers():
if not m.isfile() or not re.search(r'zip/unzipFromArrayBuffer|export/readXlsxFileBrowser', m.name):
continue
text = tf.extractfile(m).read().decode('utf-8', 'replace')
print(f'FILE {m.name}')
for i, line in enumerate(text.splitlines(), 1):
print(f'{i}:{line}')
PYRepository: stablyai/orca
Length of output: 42410
🏁 Script executed:
python3 - <<'PY'
import io, re, tarfile, urllib.request
url = 'https://registry.npmjs.org/read-excel-file/-/read-excel-file-9.3.12.tgz'
tf = tarfile.open(fileobj=io.BytesIO(urllib.request.urlopen(url, timeout=20).read()), mode='r:gz')
for m in tf.getmembers():
if not m.isfile() or m.name.endswith('.map'):
continue
text = tf.extractfile(m).read().decode('utf-8', 'replace')
if not re.search(r'unzipFromArrayBuffer|readXlsxFileBrowser|readXlsxFileUniversal|unzipFromStream', text):
continue
print(f'FILE {m.name}')
lines = text.splitlines()
for i, line in enumerate(lines, 1):
if re.search(r'unzipFromArrayBuffer|readXlsxFileBrowser|readXlsxFileUniversal|unzipFromStream|readXlsxFile\(', line):
for j in range(max(1, i - 4), min(len(lines), i + 8) + 1):
print(f'{j}:{lines[j-1]}')
print('---')
PYRepository: stablyai/orca
Length of output: 42086
🏁 Script executed:
python3 - <<'PY'
import io, re, tarfile, urllib.request
url = 'https://registry.npmjs.org/docx-preview/-/docx-preview-0.4.1.tgz'
tf = tarfile.open(fileobj=io.BytesIO(urllib.request.urlopen(url, timeout=20).read()), mode='r:gz')
for m in tf.getmembers():
if not m.isfile() or m.name.endswith('.map'):
continue
text = tf.extractfile(m).read().decode('utf-8', 'replace')
if not re.search(r'JSZip|loadAsync|\\.file\\(', text):
continue
print(f'FILE {m.name}')
lines = text.splitlines()
for i, line in enumerate(lines, 1):
if re.search(r'JSZip|loadAsync|\\.file\\(', line):
for j in range(max(1, i - 3), min(len(lines), i + 4) + 1):
print(f'{j}:{lines[j-1]}')
print('---')
print('--- package manifest ---')
for m in tf.getmembers():
if m.name == 'package/package.json':
print(tf.extractfile(m).read().decode('utf-8', 'replace'))
PYRepository: stablyai/orca
Length of output: 974
🏁 Script executed:
python3 - <<'PY'
import io, re, tarfile, urllib.request
url = 'https://registry.npmjs.org/docx-preview/-/docx-preview-0.4.1.tgz'
tf = tarfile.open(fileobj=io.BytesIO(urllib.request.urlopen(url, timeout=20).read()), mode='r:gz')
for m in tf.getmembers():
if not m.isfile() or m.name.endswith('.map'):
continue
text = tf.extractfile(m).read().decode('utf-8', 'replace')
if not re.search(r'JSZip|loadAsync|\.file\(', text):
continue
print(f'FILE {m.name}')
lines = text.splitlines()
for i, line in enumerate(lines, 1):
if re.search(r'JSZip|loadAsync|\.file\(', line):
for j in range(max(1, i - 3), min(len(lines), i + 4) + 1):
print(f'{j}:{lines[j-1]}')
print('---')
print('--- package manifest ---')
for m in tf.getmembers():
if m.name == 'package/package.json':
print(tf.extractfile(m).read().decode('utf-8', 'replace'))
PYRepository: stablyai/orca
Length of output: 41676
Reject short ZIP inputs and cap decompressed output.
findEndOfCentralDirectory can pass a negative offset to DataView.getUint32 for inputs shorter than 22 bytes. Return false before scanning, and validate the matching end record.
The main risk is not local-header size selection. docx-preview delegates to JSZip, which can inflate data before checking the actual output length. The browser path of read-excel-file uses fflate's asynchronous unzip path, which has no fixed output cap for highly compressed entries. A crafted entry can therefore declare less than 256 MiB in the central directory but make the renderer process much more data.
Enforce the 256 MiB limit during decompression, or use APIs with a hard output limit. Do not rely only on central-directory metadata.
🐛 Suggested fix
function findEndOfCentralDirectory(view: DataView): number | null {
+ if (view.byteLength < END_RECORD_BYTES) {
+ return null
+ }
const lowest = Math.max(0, view.byteLength - END_RECORD_BYTES - MAX_COMMENT_BYTES)
for (let offset = view.byteLength - END_RECORD_BYTES; offset >= lowest; offset -= 1) {
if (view.getUint32(offset, true) === END_OF_CENTRAL_DIRECTORY) {
+ const commentLength = view.getUint16(offset + 20, true)
+ if (offset + END_RECORD_BYTES + commentLength !== view.byteLength) {
+ continue
+ }
return offset
}
}Read-only viewer for .xlsx, .xlsm, .xlsb, .xls and .ods files, on Orca's contentKind "bytes" custom editor point. Bundles SheetJS Community Edition 0.20.3 (Apache-2.0) as one offline HTML file: sheet tabs, a virtualized grid, formulas and stored values in the cell bar, keyboard navigation, copy as TSV, grid semantics for screen readers, and theme-aware styling. The zip-bomb guard is adapted from stablyai/orca#29678. Co-authored-by: nebourocket <[email protected]>
ELI5
Before, opening a Word, PowerPoint or Excel file in Orca showed "Binary file — cannot display". Now the tab shows the document itself: Word pages, PowerPoint slides, and Excel sheets as a table. It is view-only, the same as the PDF preview.
What Changed
Before:
.docx,.pptxand.xlsxtabs showed "Binary file — cannot display".After: they open as read-only previews, with a footer label ("Word preview" / "PowerPoint preview" / "Excel preview") like the PDF viewer.
How it works:
src/shared/office-document-mime-types.ts) and spread it into the three tables that decide this: local IPC (filesystem-file-content-inspection.ts), runtime / SSH previews (file-preview-budget.ts), and the renderer's paged remote reads (runtime-paged-file-read.ts). One table keeps the three routes in step. Size limits stay as they are (50 MB local, the existing RPC budget remotely).ImageVieweralready branches toPdfViewerby MIME type. It now branches Office MIME types to a newoffice/OfficeDocumentViewer, which lazy-loads one renderer per format in its own chunk:docx-preview(renderAltChunks: false, so no author HTML in an iframe)@aiden0z/pptx-renderer(its recommended zip limits, windowed and lazy slides, PDF.js fallback off)read-excel-file, drawn with the existing read-onlyCsvGrid, plus sheet tabsisChatImage) is now limited toimage/*instead of "every previewable type except PDF". Without this change, Office files would have become chat images.http(s)links go through the existing CSV/markdown link routing.#bookmarklinks scroll inside the preview. Every other scheme is ignored.Why
Office files are common in agent workspaces: reports, decks and data that agents produce or read. Today, checking one means leaving Orca.
Alternatives I considered:
Known limits: the preview is read-only. Excel shows cell values (cached formula results), not formatting or charts. PowerPoint rendering is browser-based, so complex effects and missing fonts can differ from PowerPoint. Legacy
.doc/.ppt/.xlsare not handled.Linked Issue
Fixes #8301
Visual Proof
Before: these tabs showed "Binary file — cannot display". After (hidden-window Electron captures from the new e2e spec):
Word

PowerPoint

Excel (sheet tabs at the bottom)

Testing
Automated tests:
tests/e2e/office-document-preview.spec.ts, using small generated fixtures intests/e2e/fixtures/office/. It opens all three formats, checks the rendered content, and switches Excel sheets. It passes with--project=electron-headless.xlsx-sheet-grid(cell text and padding),office-zip-budget(budget accept and refuse, non-zip input), local read of a.docx(MIME and base64), chat-image refusal of.pptx, and rendererpreviewableBinaryMimeTypefor Office extensions.Checks run:
pnpm tcpnpm run check:code-quality:changedoxlintcheck:max-lines-ratchetPlatforms: tested on Linux (WSL2). Not tested on macOS, Windows or a real SSH host. The change is platform-neutral renderer code, plus MIME-table entries on the existing read paths.
AI Disclosure
Written with Claude Code (Claude Opus 5.5). I reviewed the code and verified it with the tests above.
Review
Agent skill upstream boundary
Notes
eval.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred). Typecheck, the changed-code gate, oxlint, localization checks, the related tests and the electron-vite build pass locally. CI will cover the full suites.