-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Buffer over/underrun using UBJson? #1288
Comments
Thanks for reporting, but without any further information on the input, the nature of the error, example code, etc., it is difficult to act upon the issue. Any hint is greatly appreciated! |
Yes, I understand and will see if I can set some time aside to dig deeper and create a repro case. |
Have more information. After jostling the code around a little, my debugger started to show me that to_ubjson is actually throwing an exception (why it wasn't showing that all along is concerning and I haven't pursued it yet, but probably not related to this library). [json.exception.out_of_range.407] number overflow serializing 18446744073709551516 Adding a try/catch block suppresses the error and the memory corruption originally described goes away, so I suspect that is symptomatic of the exception handling problem rather than the json library. That value is, of course, 0xffffffffffffff9c and therefore only representable (among the primitive types) as uint64_t. Is this not representable in UBJSON, or is there an oversight near line 766 of binary_writer.cpp? |
If I interpret http://ubjson.org/type-reference/value-types/#numeric correctly, then UBJSON only supports signed 64 bit integers, so I can reproduce your issue with #include "json.hpp"
using nlohmann::json;
int main()
{
json j = 18446744073709551516;
auto x = json::to_ubjson(j);
} Throwing
So I would say the library works as expected, right? |
Given that UBJSON is, ummm, "limited" (broken if I'm less charitable)... then yes, your library is working correctly. |
UBJSON still has a "high-precision number type" which is basically the string representation of the number:
The library does not support this. Do you think this would be helpful? |
Not to me -- I won't use UBJSON now that I know it doesn't support unsigned 64-bit. If I were forced to then, yes, it would be useful as I tend to have a lot of max or near-max uint64_t values. |
I would go with CBOR if possible. |
One thing that would be nice (as a user of the library) would be if somehow the message from the exception could state that this is a limitation of the chosen format. Otherwise it isn't obvious why the value is out of range. |
What do you mean? Something like
or what would you propose? |
Yeah, that would be helpful. It points out to the user that its not a bug per se, but a format limitation. |
This commit is the equivalent of #1282 for CBOR, MessagePack, and UBJSON.
I'm using 3.2.0 and have stumbled upon what seems like a buffer over or underrun error.
std::vector<uint8_t> output;
json object = SerializeMyData(data);
json::to_ubjson(object, output);
This operation appears to work, however afterward there is a problem that appears to be caused by memory elsewhere being corrupted. If I replace to_ubjson with to_cbor, to_msgpack, or dump the problem does not occur.
The code in question is buried deep in other code and the data difficult to extract, so creating a repro case will take some effort which I can't spare at the moment. Plus I was just trying to_ubjson out of curiosity to compare sizes, so this isn't a blocking issue for me. A quick search doesn't turn up an existing issue. I submit this issue in case it is enough information for the author to zero in on a potential problem, or if someone else has seen something similar.
The text was updated successfully, but these errors were encountered: