Infinite loop in XLSX.stream.to_json due to hidden row in Excel sheet #3176

Closed
opened 2024-08-14 11:57:15 +00:00 by deepak-negi-web · 0 comments
Contributor

97_node.js

stream._read = function() {
		while(R <= r.e.r) {
			if ((rowinfo[R-1]||{}).hidden) continue;
			var row = make_json_row(sheet, r, R, cols, header, hdr, dense, o);
			++R;
			if((row.isempty === false) || (header === 1 ? o.blankrows !== false : !!o.blankrows)) {
				stream.push(row.row);
				return;
			}
		}
		return stream.push(null);
	};

Hi @SheetJSDev !

This line if ((rowinfo[R-1]||{}).hidden) continue; checks if the current row R is hidden in the spreadsheet. If the row is hidden, the loop uses the continue statement to skip processing the current row and move to the next iteration of the loop but without incrementing R. This leads to an infinite loop and XLSX.stream.to_json doesn't ends.

Also (rowinfo[R-1] || {}).hidden accesses the current row information assuming the current row number R in a one-based index but on debugging i found out the current Row R is a zero-based index.
So even using if ((rowinfo[R-1]||{}).hidden) { ++R; continue; }; will push wrong data where the hidden row is included in the stream and the next non-hidden row is skipped.

I'll be submitting a pull request to fix this issue that I have found.
Please verify and merge the changes as soon as possible as I am using this library in production in my system.

### 97_node.js ``` stream._read = function() { while(R <= r.e.r) { if ((rowinfo[R-1]||{}).hidden) continue; var row = make_json_row(sheet, r, R, cols, header, hdr, dense, o); ++R; if((row.isempty === false) || (header === 1 ? o.blankrows !== false : !!o.blankrows)) { stream.push(row.row); return; } } return stream.push(null); }; ``` **Hi @SheetJSDev !** This line `if ((rowinfo[R-1]||{}).hidden) continue;` checks if the current row `R` is hidden in the spreadsheet. If the row is hidden, the loop uses the continue statement to skip processing the current row and move to the next iteration of the loop but without incrementing R. This leads to an infinite loop and XLSX.stream.to_json doesn't ends. Also `(rowinfo[R-1] || {}).hidden` accesses the current row information assuming the current row number `R` in a one-based index but on debugging i found out the current Row `R` is a zero-based index. So even using ```if ((rowinfo[R-1]||{}).hidden) { ++R; continue; };``` will push wrong data where the hidden row is included in the stream and the next non-hidden row is skipped. I'll be submitting a pull request to fix this issue that I have found. Please verify and merge the changes as soon as possible as I am using this library in production in my system.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#3176
No description provided.