From d5ebae0905751cf25c72b9ad1d97c830ee851ae0 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Thu, 4 Jan 2024 20:07:59 -0700 Subject: [PATCH] const-oid: fix `Encoder` size check and off-by-one error The `Encoder` previously returned `Error::Length` even when there was one remaining byte in the buffer. This fixes that error and adds an edge case test. --- const-oid/src/encoder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/const-oid/src/encoder.rs b/const-oid/src/encoder.rs index 049e60ab2..e4e8a4bff 100644 --- a/const-oid/src/encoder.rs +++ b/const-oid/src/encoder.rs @@ -80,7 +80,7 @@ impl Encoder { let nbytes = base128_len(arc); // Shouldn't overflow on any 16-bit+ architectures - if self.cursor + nbytes + 1 >= ObjectIdentifier::MAX_SIZE { + if self.cursor + nbytes + 1 > MAX_SIZE { return Err(Error::Length); }