Skip to content

Commit c5ff7b7

Browse files
committed
Check that cursor is empty before returning parsed ids
Checking that the cursor is empty before returning parsed ids ensure that the parser consumes the whole input and does not generate an id from a prefix of the input.
1 parent fc01198 commit c5ff7b7

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

crates/types/src/identifiers.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ impl FromStr for InvocationUuid {
385385

386386
// ulid (u128)
387387
let raw_ulid: u128 = decoder.cursor.decode_next()?;
388+
389+
if decoder.cursor.remaining() != 0 {
390+
return Err(IdDecodeError::Length);
391+
}
392+
388393
Ok(Self::from(raw_ulid))
389394
}
390395
}
@@ -743,6 +748,11 @@ impl FromStr for InvocationId {
743748
// ulid (u128)
744749
let raw_ulid: u128 = decoder.cursor.decode_next()?;
745750
let inner = InvocationUuid::from(raw_ulid);
751+
752+
if decoder.cursor.remaining() != 0 {
753+
return Err(IdDecodeError::Length);
754+
}
755+
746756
Ok(Self {
747757
partition_key,
748758
inner,

crates/types/src/vqueues/entry_id.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,21 @@ impl FromStr for VQueueEntryId {
9595
InvocationId::RESOURCE_TYPE => {
9696
let partition_key: PartitionKey = decoder.cursor.decode_next()?;
9797
let raw: [u8; REMAINDER_LEN] = decoder.cursor.decode_next::<u128>()?.to_be_bytes();
98+
99+
if decoder.cursor.remaining() != 0 {
100+
return Err(IdDecodeError::Length);
101+
}
102+
98103
Ok(Self::Invocation(partition_key, raw))
99104
}
100105
StateMutationId::RESOURCE_TYPE => {
101106
let partition_key: PartitionKey = decoder.cursor.decode_next()?;
102107
let raw: [u8; REMAINDER_LEN] = decoder.cursor.decode_next::<u128>()?.to_be_bytes();
108+
109+
if decoder.cursor.remaining() != 0 {
110+
return Err(IdDecodeError::Length);
111+
}
112+
103113
Ok(Self::StateMutation(partition_key, raw))
104114
}
105115
_ => Err(IdDecodeError::TypeMismatch),

crates/types/src/vqueues/vqueue_id.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ impl FromStr for VQueueId {
256256
// the version of the encoded string.
257257
let rest: u128 = decoder.cursor.decode_next()?;
258258
buf.put_u128(rest);
259+
260+
if decoder.cursor.remaining() != 0 {
261+
return Err(IdDecodeError::Length);
262+
}
259263
}
260264

261265
Ok(Self(buf))

0 commit comments

Comments
 (0)