Skip to content

[BUG] Cannot read properties of undefined (reading 'anchors') when reading XLSX files with certain drawings #45

@arinagolikova

Description

@arinagolikova

🐛 Bug Report

Reading certain XLSX files that contain drawings (charts, userShapes, protected shapes) crashes with:
TypeError: Cannot read properties of undefined (reading 'anchors') at /node_modules/@protobi/exceljs/lib/xlsx/xlsx.js at XLSX.reconcile at XLSX.load

A second unguarded access exists in lib/xlsx/xform/sheet/worksheet-xform.js:

drawing.anchors.forEach(anchor => {  // CRASH if drawing is undefined

The 4.4.0-protobi.9 round-trip preservation partially mitigates this by routing chart-containing drawings to preservedDrawingsXml instead of parsing. But non-chart drawings that fail to parse (e.g., c:userShapes, certain protected files) still hit this path and crash.

Lib version: 4.4.0-protobi.9

Steps To Reproduce

  1. Open an XLSX file in Excel that contains charts or complex drawing objects
  2. Read it with @protobi/exceljs
const ExcelJS = require('@protobi/exceljs');
const wb = new ExcelJS.Workbook();
await wb.xlsx.readFile('file-with-drawings.xlsx');
  1. Observe the TypeError crash

The expected behaviour:

The file should load without crashing. Users reading these files typically only need cell data, not drawing/chart content.

References

Upstream issue: exceljs/exceljs#2591
Proposed fix from @markusjohnsson
Additional fix from @DarkTraveler

Possible solution (optional, but very helpful):

lib/xlsx/xlsx.js file, in the reconcile method on line exceljs#97— add drawing && to the guard in reconcile:
change

if (drawingRel) {

to

 if (drawing && drawingRel) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions