Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invalid allocation requests #118

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ciborium/src/value/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use super::{Error, Integer, Value};

use alloc::{boxed::Box, string::String, vec::Vec};

Check warning on line 5 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test nightly debug ciborium std

the item `Box` is imported redundantly

Check warning on line 5 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test nightly debug ciborium std

the item `String` is imported redundantly

Check warning on line 5 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test nightly release ciborium std

the item `Box` is imported redundantly

Check warning on line 5 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test nightly release ciborium std

the item `String` is imported redundantly
use core::iter::Peekable;
use core::{iter::Peekable, mem::size_of};

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test beta debug ciborium std

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test 1.70.0 debug ciborium

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test beta debug ciborium

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test beta release ciborium std

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test 1.70.0 debug ciborium std

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test beta release ciborium

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test 1.70.0 release ciborium std

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test 1.70.0 release ciborium

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test nightly release ciborium

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test nightly debug ciborium

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test stable release ciborium

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test stable release ciborium std

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test stable debug ciborium

unused import: `mem::size_of`

Check failure on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / cargo clippy

unused import: `mem::size_of`

Check warning on line 6 in ciborium/src/value/de.rs

View workflow job for this annotation

GitHub Actions / test stable debug ciborium std

unused import: `mem::size_of`

use ciborium_ll::tag;
use serde::de::{self, Deserializer as _};
Expand Down Expand Up @@ -124,7 +124,9 @@

#[inline]
fn visit_map<A: de::MapAccess<'de>>(self, mut acc: A) -> Result<Self::Value, A::Error> {
let mut map = Vec::<(Value, Value)>::with_capacity(acc.size_hint().unwrap_or(0));
let mut map = Vec::<(Value, Value)>::with_capacity(
acc.size_hint().filter(|&l| l < 1024).unwrap_or(0),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description says:

Only preallocate up to 1024 Value objects.

But this code will not allocate at all when size hint >= 1024.

);

while let Some(kv) = acc.next_entry()? {
map.push(kv);
Expand Down
Loading