@@ -86,6 +86,24 @@ func TestCols(t *testing.T) {
8686 f .Pkg .Store ("xl/worksheets/sheet1.xml" , []byte (`<worksheet><sheetData><row r="2"><c r="A" t="inlineStr"><is><t>B</t></is></c></row></sheetData></worksheet>` ))
8787 _ , err = f .Cols ("Sheet1" )
8888 assert .EqualError (t , err , newCellNameToCoordinatesError ("A" , newInvalidCellNameError ("A" )).Error ())
89+
90+ t .Run ("with_invalid_worksheet_xml" , func (t * testing.T ) {
91+ f := NewFile ()
92+ f .Sheet .Delete ("xl/worksheets/sheet1.xml" )
93+ f .Pkg .Store ("xl/worksheets/sheet1.xml" , []byte (`<worksheet><sheetData><row r="1"><c r="A1"><v>1</v></c></row><row r="2"><c r="A"2><v>2</v></c></row></sheetData></worksheet>` ))
94+ cols , err := f .Cols ("Sheet1" )
95+ assert .NoError (t , err )
96+ cnt := 0
97+ row := []string {}
98+ for cols .Next () {
99+ cnt ++
100+ row , err = cols .Rows ()
101+ assert .NoError (t , err )
102+ }
103+ assert .Equal (t , 1 , cnt )
104+ assert .Equal (t , []string {"1" }, row )
105+ assert .NoError (t , f .Close ())
106+ })
89107}
90108
91109func TestColumnsIterator (t * testing.T ) {
@@ -164,38 +182,6 @@ func TestGetColsError(t *testing.T) {
164182 assert .NoError (t , err )
165183}
166184
167- func TestColsIteratorRetainsFilePointer (t * testing.T ) {
168- // Regression for #2299: when worksheet XML is truncated before the
169- // </sheetData> close element, the SAX loop in Cols falls through to
170- // the final return. Prior to #2300 the *File pointer was only wired
171- // into the iterator inside the sheetData EndElement branch, so this
172- // path returned a Cols whose f field was nil, and a subsequent
173- // Cols.Rows call would nil-dereference on cols.f.getOptions. Make
174- // sure the iterator carries a live *File regardless of where the
175- // parse exits.
176- f := NewFile ()
177- f .Sheet .Delete ("xl/worksheets/sheet1.xml" )
178- // Missing </sheetData> and </worksheet> close tags simulate the
179- // truncation seen by the fuzzer in #2299.
180- f .Pkg .Store ("xl/worksheets/sheet1.xml" , []byte (fmt .Sprintf (
181- `<worksheet xmlns="%s"><sheetData><row r="1"><c r="A1" t="inlineStr"><is><t>v</t></is></c></row>` ,
182- NameSpaceSpreadSheet .Value )))
183- f .checked = sync.Map {}
184-
185- cols , err := f .Cols ("Sheet1" )
186- require .NoError (t , err )
187- require .NotNil (t , cols )
188- assert .NotNil (t , cols .f , "cols.f must be set even when sheetData close element is missing" )
189-
190- // Walking the iterator must not panic, even though the XML is truncated.
191- assert .NotPanics (t , func () {
192- for cols .Next () {
193- _ , _ = cols .Rows ()
194- }
195- })
196- assert .NoError (t , f .Close ())
197- }
198-
199185func TestColsRows (t * testing.T ) {
200186 f := NewFile ()
201187
0 commit comments