-
Notifications
You must be signed in to change notification settings - Fork 70
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
Non-canonical values when deserializing large integers from 32 bits arch on a 64 bits arch #148
Comments
Well spotted, thank you for reporting this corner case. It might be possible to fail at deserialization time in this case, by reporting an intentionally wrong size, but the failure message will be obscure ("input_value: incorrect length of serialized custom block"). Ideally, the custom block would be converted to an unboxed integer during deserialization, but this cannot be implemented with the current deserialization API. |
I didn't think about that — I'd say an obscure error message during deserialization is still better than silently incorrect behavior later in the program due to unexpected semantics.
This was my initial thought as well, but the deserialization API clearly was not built with arch-dependent representations in mind (you probably know this better than me). |
For what it's worth, I think that the case of an integer that was allocated on a 32-bit machine when it was serialized and is then unserialized on a 64-bit machine may already be supported in
unmarshal_z.ml is a file written to add support for Zarith integers to unmarshal.ml, an unofficial deserializer written in OCaml for values serialized with OCaml's serializer. |
For the record: it's perfectly possible to fail cleanly from a custom deserializer, using |
Ah! I failed to properly read the manual, it seems ;) I was misled by this paragraph:
I opened ocaml/ocaml#12819 to mention |
This can happen with numbers marshaled on a 32-bit platform (including from JS-of-OCaml) and unmarshaled on a 64-bit platform. Fixes: #148
It is known that deserializing on a 32 bits machine a value in the range
[2^31 .. 2^63[
that was serialized on a 64 bits machine will fail, because the value is not representable as an OCaml integer on 32 bits machines.On the other hand, deserializing on a 64 bits machine a value in that range that was serialized on a 32 bits machine (including
js_of_ocaml
) will create a non-canonical value with semantics-breaking behavior (for instance,Z.(equal (x * one) x)
does not hold).Not sure if there is anything that can be done about it (I don't think deserialization code can fail), but it might be worth documenting.
The text was updated successfully, but these errors were encountered: