Skip to content

Fail when unmarshaling would produce non-canonical big integers#149

Merged
xavierleroy merged 3 commits intoocaml:masterfrom
xavierleroy:cautious-unmarshaling
Jan 3, 2024
Merged

Fail when unmarshaling would produce non-canonical big integers#149
xavierleroy merged 3 commits intoocaml:masterfrom
xavierleroy:cautious-unmarshaling

Conversation

@xavierleroy
Copy link
Contributor

@xavierleroy xavierleroy commented Dec 11, 2023

As reported in #148, big integers marshaled on a 32-bit platform (or by JS-of-OCaml) and unmarshaled on a 64-bit platform can appear as custom blocks while the 64-bit platform expects a tagged OCaml integer. This can produce wrong results in many different ways.

This PR proposes to fail during unmarshaling in this case. The failure is obtained by returning a wrong length for the big integer. In current OCaml the error message is strange (Failure "input_value: incorrect length of serialized custom block") but I have a companion PR to improve it a bit.

Fixes: #148

@xavierleroy
Copy link
Contributor Author

Oups, bizarre closing. Reopening.

@xavierleroy xavierleroy reopened this Dec 12, 2023
@xavierleroy
Copy link
Contributor Author

I feel confident enough about this change to merge it right now.

@xavierleroy xavierleroy merged commit d0a89ee into ocaml:master Jan 3, 2024
@xavierleroy xavierleroy deleted the cautious-unmarshaling branch January 3, 2024 13:17
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

Successfully merging this pull request may close these issues.

Non-canonical values when deserializing large integers from 32 bits arch on a 64 bits arch

1 participant