locka99 / opcua

A client and server implementation of the OPC UA specification written in Rust
Mozilla Public License 2.0
501 stars 131 forks source link

types/variant: fix cast to i32 that might result in negative number #200

Closed laumann closed 2 years ago

laumann commented 2 years ago

When array_length is decoded and greater than zero, the configured decoding options are checked, casting max_array_length to i32. The type is a usize. We set max_array_length = usize::MAX, resulting the cast to produce -1 (as an i32) and returning BadEncodingLimitsExceeded.

Given that array_length is cast to a usize immediately after this check, it makes sense to first convert to it to usize and perform the comparison on usize instead of i32.