Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endless loop in constructor with empty ByteArrayInputStream #56

Closed
mikrovvelle opened this issue Dec 27, 2019 · 2 comments
Closed

Endless loop in constructor with empty ByteArrayInputStream #56

mikrovvelle opened this issue Dec 27, 2019 · 2 comments
Assignees

Comments

@mikrovvelle
Copy link

The following code, using the SasFileReaderImpl class, will lead to an endless loop:

  byte[] emptyArray = new byte[0];
  ByteArrayInputStream emptyStream = new ByteArrayInputStream(emptyArray);
  SasFileReaderImpl emptyByteArrayStreamReader = new SasFileReaderImpl(emptyStream);

Probably no one should be passing in empty ByteArrayInputStreams to the constructor, but instead of getting caught in an endless loop, it would be helpful to throw an exception instead. This would allow classes extending SasFileReaderImpl to easily catch this kind of bad input.


The loop takes place in getBytesFromFile in SasFileParser, line 750:

  while (actuallySkipped < offset[i] - currentFilePosition) {
    try {
      actuallySkipped += sasFileStream.skip(offset[i] - currentFilePosition - actuallySkipped);
    } catch (IOException e) {
      // never reach this far

actuallySkipped and currentFilePosition are stuck at 0, while offset[0] is 32, so the while statement never exits.

@syjer
Copy link

syjer commented Dec 27, 2019

Hi, I was kinda reluctant to open the issue here, as it has an impact on the Apache Tika project and I was trying to figure out who to contact and how.

You can do a Denial of Service with a correctly crafted input, so this issue is quite important.

See the gists: https://gist.github.com/syjer/9ffebab4538fbc4242d10e50fa5a4454

mikrovvelle pushed a commit to mikrovvelle/nifi-marklogic-sas that referenced this issue Jan 3, 2020
xantorohara added a commit to xantorohara/parso that referenced this issue Dec 29, 2020
epam#56 Fixed infinity loop on empty or incomplete input stream
xantorohara added a commit to xantorohara/parso that referenced this issue Dec 29, 2020
epam#56 Fixed infinity loop on empty or incomplete input stream
printsev pushed a commit that referenced this issue Dec 29, 2020
* #58 Fixed infinity loop on broken file
#56 Fixed infinity loop on empty or incomplete input stream
@printsev
Copy link
Contributor

closed thanks to xantorohara

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

No branches or pull requests

4 participants