UnitTestBot / UnitTestBot/usvm

NPE when using java.io.Reader/java.io.InputStreamReader

Open
#77 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Kotlin
Stars
33
Forks
27
Avg merge
4d 3h
Merged PRs (30d)
15

Description

Maybe related with #75

Code:

    public void bad() throws Throwable
    {
        byte data;

        /* init data */
        data = -1;

        /* POTENTIAL FLAW: Read data from console with readLine*/
        BufferedReader readerBuffered = null;
        InputStreamReader readerInputStream = null;
        try
        {
            readerInputStream = new InputStreamReader(System.in, "UTF-8");
            readerBuffered = new BufferedReader(readerInputStream);
            String stringNumber = readerBuffered.readLine();
            if (stringNumber != null)
            {
                data = Byte.parseByte(stringNumber.trim());
            }
        }
        catch (IOException exceptIO)
        {
            IO.logger.log(Level.WARNING, "Error with stream reading", exceptIO);
        }
        catch (NumberFormatException exceptNumberFormat)
        {
            IO.logger.log(Level.WARNING, "Error with number parsing", exceptNumberFormat);
        }
        finally
        {
            /* clean up stream reading objects */
            try
            {
                if (readerBuffered != null)
                {
                    readerBuffered.close();
                }
            }
            catch (IOException exceptIO)
            {
                IO.logger.log(Level.WARNING, "Error closing BufferedReader", exceptIO);
            }
            finally
            {
                try
                {
                    if (readerInputStream != null)
                    {
                        readerInputStream.close();
                    }
                }
                catch (IOException exceptIO)
                {
                    IO.logger.log(Level.WARNING, "Error closing InputStreamReader", exceptIO);
                }
            }
        }

        /* POTENTIAL FLAW: if data == Byte.MAX_VALUE, this will overflow */
        byte result = (byte)(data + 1);

        IO.writeLine("result: " + result);

Unexpected NPEs

Instruction: throw %0
Exception: JcException: Address: 0x3, type: java.lang.NullPointerException
Call stack (contains 3 frames):
	0: UCallStackFrame(method=(id:73)javajuliet.testcase.CWE190_Integer_Overflow.CWE190_Integer_Overflow__byte_console_readLine_add_01#bad(), returnSite=null)
	1: UCallStackFrame(method=(id:1)java.io.InputStreamReader#<init>(java.io.InputStream, java.lang.String), returnSite=%3.<init>(%4, "UTF-8"))
	2: UCallStackFrame(method=(id:1)java.io.Reader#<init>(java.lang.Object), returnSite=this.<init>(arg$0))
Instruction: %0.close()
Exception: JcException: Address: 0x4, type: java.lang.NullPointerException
Call stack (contains 2 frames):
	0: UCallStackFrame(method=(id:73)javajuliet.testcase.CWE190_Integer_Overflow.CWE190_Integer_Overflow__byte_console_readLine_add_01#bad(), returnSite=null)
	1: UCallStackFrame(method=(id:1)java.io.InputStreamReader#close(), returnSite=%3.close())

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the provided CWE190 testcase and trace the java.io.InputStreamReader constructor, java.io.Reader constructor, and InputStreamReader.close() calls shown in the stack traces. The work is complete when these operations no longer produce the reported NullPointerExceptions during execution and cleanup.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.