ValveKeyValue icon indicating copy to clipboard operation
ValveKeyValue copied to clipboard

FormatException with an unparseable hex number

Open xPaw opened this issue 1 year ago • 2 comments

"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.

xPaw avatar Sep 15 '24 20:09 xPaw

"loose checks on the a/A characters"?

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

yaakov-h avatar Sep 16 '24 00:09 yaakov-h

"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?

xPaw avatar Sep 16 '24 07:09 xPaw