ValveResourceFormat / ValveKeyValue

📃 Next-generation Valve's key value framework for .NET
https://www.nuget.org/packages/ValveKeyValue/
MIT License
151 stars 39 forks source link

FormatException with an unparseable hex number #105

Open xPaw opened 2 months ago

xPaw commented 2 months ago
"a" {
    "key" "0x11223344556677[]"
}

It passes the 0x prefix and 18 total length check but then fails to parse from hex. Valve's code kind of doesn't care because they do loose checks on the a/A characters and then math it.

I also noticed we check for 0x case insensitive, but valve only checks for lower case x.

yaakov-h commented 2 months ago

"loose checks on the a/A characters"?

What is this expected to be parsed as - what value does it result in?

xPaw commented 2 months ago

"loose checks on the a/A characters"?

They don't check the ranges fully.

                for( int i=2; i < 2 + 16; i++ )
                {
                    char digit = value[i];
                    if ( digit >= 'a' ) 
                        digit -= 'a' - ( '9' + 1 );
                    else
                        if ( digit >= 'A' )
                            digit -= 'A' - ( '9' + 1 );
                    retVal = ( retVal * 16 ) + ( digit - '0' );
                }

What is this expected to be parsed as

Looking at that code, probably nothing useful. Maybe we should fallback to not parsing it and return a string?