Bug? Old KVS1: some strings are treated as float

jmon

Well-Known Member
Licensed User
Hi,

I think I found a bug with the old KVS. I know, I must be one of the only sticking with the first version of KVS1, but I can't upgrade it at the moment!

The bug is that if I putSimple this:
B4X:
KVS.PutSimple("ColorAccent", "0e9395")
The data stored in KVS is actually this:
"ColorAccent": 0
I tried to figure out what's happening, and it could be because any string starting with "0e" is treated as float : https://www.whitehatsec.com/blog/magic-hashes/

I guess the problem with KVS1 was that the type of the column wasn't specified:
B4X:
sql1.ExecNonQuery("CREATE TABLE IF NOT EXISTS main(key TEXT PRIMARY KEY, value NONE)")
so that allows the string to be treated as float.

I know it's a random case, but I figured I should post it, for learning purposes, and it took me quite a while to figure out the problem :)
 

Erel

Administrator
Staff member
Licensed User
It is a limitation of the old KVS implementation where the type information of "simple" values are lost.
 

emexes

Well-Known Member
Licensed User
I have a vague recollection of similar confusion in C (I think it was) where integers with leading zeros were interpreted as octal.

X = 23 'twenty-three
X = 023 'nineteen

I was surprised that your 0e9395 didn't crap out with an exponent-too-large error because single precision floats ("E") have a maximum exponent of 38, and double precision floats (which I thought were "D") have a maximum exponent of 308. But 0eANYTHING still equals 0, so... fair enough... :)
 
Top