tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.49k stars 418 forks source link

xlnt::streaming_workbook_reader::has_cell() returns spurious true given empty row #492

Closed adamhooper closed 3 years ago

adamhooper commented 4 years ago

When faced with a self-closing <row/> tag (which is valid), this code will fail its assertion:

while (wbr.has_cell()) {
    const xlnt::cell& cell(wbr.read_cell());
    assert(cell != nullptr);
    // do something...
}

That's because of this line in xlsx_consumer::read_cell():

    if (!in_element(qn("spreadsheetml", "row")))
    {
        return cell(nullptr);
    }

That's an invalid cell. And there's no way to compare against it in my own code, because I can't initialize such a cell or read its d_ member. So I can't see a way to parse the workbook with the streaming parser without segfaulting.

The only way to know whether there's another cell is to parse until it's found. That implies a while loop somewhere in xlsx_consumer::read_cell().

Pull request pending.