Skip to content

Commit

Permalink
Fix SDF parsing to avoid overflow error
Browse files Browse the repository at this point in the history
The while loop should stop executing its body in two scenarios:

- When it finds the string "$$$$" at the offset index within the lines array.
- When the offset index reaches or exceeds the length of the lines array.

The second check was not being performed.
  • Loading branch information
dxdc committed Sep 22, 2023
1 parent ebdd0f8 commit 7cd8ed8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/parsers/SDF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var parseV2000 = function (lines: any, options: ParserOptionsSpec) {
}
if (options.multimodel) {
if (!options.onemol) atoms.push([]);
while (lines[offset] !== "$$$$") offset++;
while (lines[offset] !== "$$$$" && offset < lines.length) offset++;
lines.splice(0, ++offset);
} else {
break;
Expand Down Expand Up @@ -148,7 +148,7 @@ var parseV3000 = function (lines: any, options: ParserOptionsSpec) {
if (!options.onemol) {
atoms.push([]);
}
while (lines[offset] !== "$$$$") {
while (lines[offset] !== "$$$$" && offset < lines.length) {
offset++;
}
lines.splice(0, ++offset);
Expand Down

0 comments on commit 7cd8ed8

Please sign in to comment.