Skip to content

Undefined index: height exception on reading vmlDrawings #1347

@malles

Description

@malles

This is:

- [x] a bug report
- [ ] a feature request
- [x] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

Similar closed issue (stale): #888

What is the expected behavior?

Styled vmlDrawings can be read from an xlsx file, or will at least not crash the reader..

What is the current behavior?

In some examples the reader throws exception Undefined index: height on Xlsx.php (line 1048).

What are the steps to reproduce?

I have found this issue in various XLSX files.
Consider an XML with a vmlDrawing like this

<v:shape id="CheckBox3" o:spid="_x0000_s4106" type="#_x0000_t201"
  style='position:absolute;margin-left:424.5pt;margin-top:169.5pt;width:67.5pt;
  height:13.5pt;z-index:5;mso-wrap-style:tight' fillcolor="white [9]"
  stroked="f" strokecolor="windowText [64]" strokeweight="3e-5mm" o:insetmode="auto">
  <v:fill color2="white [9]"/>
  <v:imagedata o:relid="rId5" o:title=""/>
  <v:shadow color="black" obscured="t"/>
  <x:ClientData ObjectType="Pict">
   <x:SizeWithCells/>
   <x:Anchor>
    42, 1, 13, 1, 46, 28, 13, 19</x:Anchor>
   <x:AutoFill>False</x:AutoFill>
   <x:AutoLine>False</x:AutoLine>
   <x:FmlaLink>Sheet2!E41</x:FmlaLink>
   <x:CF>Pict</x:CF>
   <x:AutoPict/>
   <x:MapOCX/>
  </x:ClientData>
 </v:shape>

The style from the shape is extracted via Xlsx::toCSSArray. Here the newlines are stripped:

$style = trim(str_replace(["\r", "\n"], '', $style), ';');.

As a result, the whitespace from the tab is not trimmed;

position:absolute;margin-left:424.5pt;margin-top:169.5pt;width:67.5pt; height:13.5pt;z-index:5;mso-wrap-style:tight.

This leaves the spaces in the key for height in the resulting style array:
image

This leads to $hfImages[(string) $shape['id']]->setHeight($style['height']); (src) throwing the Undefined index: height exception.

Proposed fix

Also replace the spaces in Xlsx::toCSSArray;

$style = trim(str_replace(["\r", "\n", ' '], '', $style), ';');

Which versions of PhpSpreadsheet and PHP are affected?

Most recent (1.10.1).

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