RestComm / jain-sip

Disclaimer: This repository is a git-svn mirror of the project found at http://java.net/projects/jsip whose original repository is developed collaboratively by the Advanced Networking Technologies Division at the National Institute of Standards and Technology (NIST) - an agency of the United States Department of Commerce and by a community of individual and enterprise contributors. TeleStax, Inc. will perform some productization work, new features experimentation branches, etc for its TelScale jSIP product that doesn't concern the community from the main repository hence this git repository.
http://www.restcomm.com/
141 stars 151 forks source link

Process is taking huge memory due to creation of 2 billion character "<". #187

Open Sujith-G opened 5 years ago

Sujith-G commented 5 years ago

Issue: Process is taking huge memory due to creation of 2 billion character "<". This will also lead to OutOfMemoryError within the process.

Reason: In Class MediaFieldParser.java -- MediaFieldParser.mediaField() if (Debug.parserDebug) Check is missing in the below code. dbg_leave("mediaField"); is being called without the 'if (Debug.parserDebug)' check.

    } finally {
        dbg_leave("mediaField");
    }

ParserCore.dbg_enter(String rule) are not called since debugging is not enabled at the process. In ParserCore.dbg_leave(String rule) nesting_level variable will be decremented by one every functioncall. Finally after 2147483647 function calls, The nesting_level variable will have -2147483648. On the next function call -2147483648 -1, Will nesting_level variable will have the value of 2147483647. This leads to the creation of 2147483647 characters '<' .

protected void dbg_leave(String rule) {
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < nesting_level ; i++)
        stringBuilder.append("<");

    if (debug)  {
        System.out.println(
            stringBuilder +
            rule +
            "\nlexer buffer = \n" +
            lexer.getRest());
    }
    nesting_level --;
}

Fix: Please add if (Debug.parserDebug) in MediaFieldParser.mediaField(). } finally { if (Debug.parserDebug) dbg_leave("mediaField"); }