Skip to content

Commit d6b519b

Browse files
committed
fix: use allocating deserializers when scratch space exceeded
Issue enarx#32 describes a class of errors where `deserialize_str` (and `deserialize_bytes`) have match expressions that fall through to an error when the `Text` (`Bytes`) lengths are longer than can fit in the scratch array. This patch works around that limitation by delegating to the corresponding allocating methods `deserialize_string` (`deserialize_byte_buf`) in case the scratch space is too small. This should address the issue even for types whose `Deserialize` visitor does not implement `visit_string`, since the default implementation of that method delegates back to `visit_str` once the fully-deserialized `String` is in hand. This addition raises a question to me about the stance of the `ciborium` crate on `no_std`/`alloc` support. This workaround depends on being able to use `String` and `Vec`, which rules out `no_std`. But these allocating deserializers already exist in the code and don't appear to be guarded by `cfg` directives, so I don't believe this patch changes the level of support provided for these environments.
1 parent 109c371 commit d6b519b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ciborium/src/de/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ where
333333
}
334334
}
335335

336+
// Longer strings require alloaction; delegate to `deserialize_string`
337+
item @ Header::Text(_) => {
338+
self.decoder.push(item);
339+
self.deserialize_string(visitor)
340+
}
341+
336342
header => Err(header.expected("str")),
337343
};
338344
}
@@ -371,6 +377,12 @@ where
371377
visitor.visit_bytes(&self.scratch[..len])
372378
}
373379

380+
// Longer byte sequences require alloaction; delegate to `deserialize_byte_buf`
381+
item @ Header::Bytes(_) => {
382+
self.decoder.push(item);
383+
self.deserialize_byte_buf(visitor)
384+
}
385+
374386
Header::Array(len) => self.recurse(|me| {
375387
let access = Access(me, len);
376388
visitor.visit_seq(access)

0 commit comments

Comments
 (0)