Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1421)

Unified Diff: mojo/public/rust/src/bindings/encoding.rs

Issue 2220183003: Rust: Add validation to decode (Closed) Base URL: git@github.com:domokit/mojo.git@coder-testing
Patch Set: Update from upstream branches (fixed arrays, validation code, etc.) Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/rust/src/bindings/decoding.rs ('k') | mojo/public/rust/src/bindings/macros.rs » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/rust/src/bindings/encoding.rs
diff --git a/mojo/public/rust/src/bindings/encoding.rs b/mojo/public/rust/src/bindings/encoding.rs
index 1cb3a91c297d2e6604f1d469352286f66a2b6870..4e30628983e6392bb95c3acc59f6617cc7859f41 100644
--- a/mojo/public/rust/src/bindings/encoding.rs
+++ b/mojo/public/rust/src/bindings/encoding.rs
@@ -41,6 +41,13 @@ impl Bits {
1 << (self.0 & 7)
}
+ pub fn checked_mul(self, val: usize) -> Option<Bits> {
+ match val.checked_mul(self.0) {
+ Some(result) => Some(Bits(result)),
+ None => None,
+ }
+ }
+
/// Align the bits to some number of bytes.
pub fn align_to_bytes(&mut self, bytes: usize) {
self.0 = util::align_bytes(self.0, 8 * bytes);
@@ -72,7 +79,7 @@ impl Mul<usize> for Bits {
pub trait MojomNumeric: Copy + Clone + Sized + Add<Self> + Sub<Self, Output=Self> + Mul<Self> +
Div<Self, Output=Self> + Rem<Self, Output=Self> + PartialEq<Self> + Default {
- /// Converts the primitive to a little-endian representation (the mojom endianness).
+/// Converts the primitive to a little-endian representation (the mojom endianness).
fn to_mojom_endian(self) -> Self;
}
@@ -221,7 +228,10 @@ impl<'slice> EncodingState<'slice> {
///
/// Note: the encoder will not allocate a buffer for you, rather
/// a pre-allocated buffer must be passed in.
- pub fn new(buffer: &'slice mut [u8], header: &DataHeader, offset: usize) -> EncodingState<'slice> {
+ pub fn new(buffer: &'slice mut [u8],
+ header: &DataHeader,
+ offset: usize)
+ -> EncodingState<'slice> {
let mut state = EncodingState {
data: buffer,
global_offset: offset,
« no previous file with comments | « mojo/public/rust/src/bindings/decoding.rs ('k') | mojo/public/rust/src/bindings/macros.rs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698