jruizgit / rules

Durable Rules Engine
MIT License
1.14k stars 207 forks source link

Wrap around on jsonProperty::valueOffset #327

Closed JeremyWildsmith closed 4 years ago

JeremyWildsmith commented 4 years ago

valueOffset wraps around for larger JSON objects, resulting in unexpected behaviour (specifically, parse errors in my case.)

typedef struct jsonProperty {
    unsigned int hash;
    unsigned char type;
    unsigned short valueOffset;
    unsigned short valueLength;
    union {
        long long i; 
        double d; 
        unsigned char b; 
        char *s;
    } value;
} jsonProperty;

It is a fairly simple fix and just amounts to using a larger type.

To reproduce, you can use a large json object. For example, a string array where each elements could be up to 100 characters.

jruizgit commented 4 years ago

Hi Jeremy, thanks for reporting this issue. I will look into this and reply back in a few days. Since jsonProperty is a heavily used structure, I'm worried changing the type might result in significant increase in memory usage.

jruizgit commented 4 years ago

Hi, thanks for reporting this issue. I have published a fix for it. Please use version 2.0.26 (Ruby), 2.0.27 (Python), 2.0.24 (Node.js).

JeremyWildsmith commented 4 years ago

Awesome, thanks!