-
Notifications
You must be signed in to change notification settings - Fork 50
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
type uint32 = int32 is risky #86
Comments
agreed, with a a major bump in the library version |
I'm not sure whether |
@hannesm, I'd like to understand your concerns better.
Could you expand on how that (resolved) issue is relevant to using
The
I'm not sure what you mean here, either. |
On 11/05/2017 12:04, yallop wrote:
Could you expand on how that (resolved) issue is relevant to using `integers` in `cstruct`? e.g. were you hoping for some other resolution?
Let's assume I have a struct which consists of a sequence number, such
as in TLS (or OTR). The property which these should also satisfy is
"may never ever wrap around" (otherwise, you use the same IV with the
same key, and your symmetric crypto is broken).
Of course, you could represent this as a (from `integers`)
`Unsigned.Uint32.t`, and convert this to some other number
representation which is more careful about wrapping. But wouldn't you
then by construction introduce a chain of conversions: `bytes -> stdlib
int -> integers Uint32.t -> other number` -- I'd prefer to have a more
raw interface and avoid conversions where we can - esp. since cstruct
seems to be used all over.
Does this make sense? OTOH, adding a non-implicit way to handle wrap
around in integers may solve the issue.
|
Clearly, performance benchmarks of parsing e.g. |
Yes, I agree that it would be good to avoid a chain of conversions. We should certainly not go through stdlib I think the last piece of the puzzle, going from |
So what was decided on this one? |
Cstruct declares
uint32 = int32
. However,int32
is signed and doingInt32.to_int
may result in a negative number, which the calling code is unlikely to be expecting. Perhaps we should use a separate type for this, with safe accessor functions.For example, ocaml-9p does:
This can raise an exception (which the code is trying to avoid) for large values of
len
.The text was updated successfully, but these errors were encountered: