Skip to content
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

Bson serialize/deserialize bug with uint[] #538

Closed
NCrashed opened this issue Feb 19, 2014 · 1 comment
Closed

Bson serialize/deserialize bug with uint[] #538

NCrashed opened this issue Feb 19, 2014 · 1 comment

Comments

@NCrashed
Copy link
Contributor

Consider following code:

import std.stdio;

import vibe.data.bson;

void main()
{
    uint[] arr1 = [3197622861];
    auto bson = serializeToBson(arr1);
    writeln(bson);
    uint[] arr2 = bson.deserializeBson!(uint[]);
    assert(arr1 == arr2);
}

Output of the program:

[ncrashed@localhost bson-test]$ ./bson-test
[-1097344435]
std.conv.ConvOverflowException@/usr/include/dmd/phobos/std/conv.d(356): Conversion negative overflow
----------------
./bson-test(pure @safe uint std.conv.toImpl!(uint, int).toImpl(int)+0x31) [0x614859]
./bson-test(pure @safe uint std.conv.to!(uint).to!(int).to(int)+0x13) [0x614823]
./bson-test(uint vibe.data.bson.BsonSerializer.readValue!(uint).readValue()+0x5e) [0x686afe]
./bson-test(uint vibe.data.serialization.deserializeImpl!(uint, vibe.data.bson.BsonSerializer).deserializeImpl(ref vibe.data.bson.BsonSerializer)+0x15) [0x68cc7d]
./bson-test(void vibe.data.serialization.deserializeImpl!(uint[], vibe.data.bson.BsonSerializer).deserializeImpl(ref vibe.data.bson.BsonSerializer).__lambda3()+0x1a) [0x68cc2a]
./bson-test(void vibe.data.bson.BsonSerializer.readArray!(uint[]).readArray(scope void delegate(ulong), scope void delegate()).int __foreachbody4(ref vibe.data.bson.Bson)+0x54) [0x686a9c]
./bson-test(const(int function(int delegate(ref vibe.data.bson.Bson))) vibe.data.bson.Bson.opApply.int __foreachbody2(ref ulong, ref vibe.data.bson.Bson)+0x47) [0x683bb7]
./bson-test(const(int function(int delegate(ref ulong, ref vibe.data.bson.Bson))) vibe.data.bson.Bson.opApply+0x210) [0x683e58]
./bson-test(const(int function(int delegate(ref vibe.data.bson.Bson))) vibe.data.bson.Bson.opApply+0x91) [0x683b39]
./bson-test(void vibe.data.bson.BsonSerializer.readArray!(uint[]).readArray(scope void delegate(ulong), scope void delegate())+0xc9) [0x6869d1]
./bson-test(uint[] vibe.data.serialization.deserializeImpl!(uint[], vibe.data.bson.BsonSerializer).deserializeImpl(ref vibe.data.bson.BsonSerializer)+0x45) [0x68cbdd]
./bson-test(uint[] vibe.data.serialization.deserialize!(vibe.data.bson.BsonSerializer, uint[], vibe.data.bson.Bson).deserialize(vibe.data.bson.Bson)+0x41) [0x68cb91]
./bson-test(uint[] vibe.data.bson.deserializeBson!(uint[]).deserializeBson(vibe.data.bson.Bson)+0x16) [0x6868fe]
./bson-test(_Dmain+0x78) [0x608398]
./bson-test(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll().void __lambda1()+0x18) [0x769d24]
./bson-test(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x769c7e]
./bson-test(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x30) [0x769ce4]
./bson-test(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x769c7e]
./bson-test(_d_run_main+0x1a3) [0x769bff]
./bson-test(main+0x25) [0x6806dd]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x37d8621b45]
----------------

Dub project to demostrate the issue.

Platform: Fedora 19 x86_64 kernel 3.12.9-201

@NCrashed
Copy link
Contributor Author

The problem is in the line:

else static if (is(T : int)) return m_inputData.get!int().to!T;

The std.conv function don't allow overflowing and thus i cannot transfer unsigned types within bson. The easiest workaround is use 'cast' instead of 'to'. Interestingly, that long and double cases use casting and only the int case relies to 'to' function, is there any hidden sence?

s-ludwig added a commit that referenced this issue Feb 23, 2014
Fix #538. Overflow check for unsigned values is removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant