Sitelet https://github.com/stepcode/stepcode/pull/485
Skip to content

Stop FindHeaderSection spinning forever on a file with no header - #485

Open
attixray wants to merge 1 commit into
stepcode:developfrom
attixray:sc-fix-header-scan-hang
Open

Stop FindHeaderSection spinning forever on a file with no header#485
attixray wants to merge 1 commit into
stepcode:developfrom
attixray:sc-fix-header-scan-hang

Conversation

@attixray

Copy link
Copy Markdown

STEPfile::FindHeaderSection() loops on in.getline( buf, BUFSIZ, ';' ) looking for HEADER, and exits only via eof(). A file with no ; in its first BUFSIZ bytes — a binary file handed to the reader by mistake, say — sets failbit and leaves buf unchanged. getline then does nothing on every subsequent call, eof() never becomes true, and the loop spins forever on a single-character diet.

Check fail(), report it as an input error, and return.

getline(buf, BUFSIZ, ';') on a stream whose next BUFSIZ bytes contain no
semicolon sets failbit and leaves buf unchanged. The scan loop only tests
eof(), which never arrives once failbit is set, so it never terminates - hand
it any binary file and it hangs instead of reporting that the file is not
STEP. Treat a failed extraction the same as end of file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant