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

Unexpected NumberFormatException in YAMLParser #454

Closed
arthurscchan opened this issue Jan 17, 2024 · 0 comments
Closed

Unexpected NumberFormatException in YAMLParser #454

arthurscchan opened this issue Jan 17, 2024 · 0 comments
Labels
2.17 Fix or feature targeted at 2.17 release yaml Issue related to YAML format backend
Milestone

Comments

@arthurscchan
Copy link
Contributor

In the YAMLParser::_parseNumericValue() method, there is a call to Integer.parseInt(String) method which parse the _cleanedTextValue string into integer. Since the _cleanedTextValue string is coming from untrusted user input, it could be malformed and make the Integer.parseInt(String) method throws a NumberFormatException. There is no handling of NumberFormatException and thus it will throw directly to the user as an unexpected exception. Also, the call to org.yaml.snakeyaml.parser.ParserImpl::getEvent() also could throw NumberFormatException. That will also cause the same problem as above.

    @Override
    protected void _parseNumericValue(int expType) throws IOException
    {
        // Int or float?
        if (_currToken == JsonToken.VALUE_NUMBER_INT) {
            int len = _cleanedTextValue.length();
            if (_numberNegative) {
                len--;
            }
            if (len <= 9) { // definitely fits in int
                _numberInt = Integer.parseInt(_cleanedTextValue);
                _numTypesValid = NR_INT;
                return;
            }
...
    public JsonToken nextToken() throws IOException
    {
        _currentIsAlias = false;
        _binaryValue = null;
        if (_closed) {
            return null;
        }

        while (true) {
            Event evt;
            try {
                evt = _yamlParser.getEvent();
,,,

The suggested fix is to add a try-catch wrapper to wrap the NumberFormatException with the expected JacksonException to avoid unexpected exceptions thrown to the users.

We found this issue by OSS-Fuzz and it is reported in https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=63274 https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65855.

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=63274 is already fixed in #452.

@cowtowncoder cowtowncoder changed the title Unexpected NumberFormatException in YAMLParser Unexpected NumberFormatException in YAMLParser Jan 18, 2024
@cowtowncoder cowtowncoder added yaml Issue related to YAML format backend 2.17 Fix or feature targeted at 2.17 release labels Jan 18, 2024
@cowtowncoder cowtowncoder added this to the 2..17.0 milestone Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.17 Fix or feature targeted at 2.17 release yaml Issue related to YAML format backend
Projects
None yet
Development

No branches or pull requests

2 participants