mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-23 04:51:03 +00:00
Clamp hints coming from untrusted input to 4096
This commit is contained in:
+2
-1
@@ -114,6 +114,7 @@ impl<'a> ser::Serialize for Bytes<'a> {
|
|||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
#[cfg(any(feature = "std", feature = "collections"))]
|
||||||
mod bytebuf {
|
mod bytebuf {
|
||||||
|
use core::cmp;
|
||||||
use core::ops;
|
use core::ops;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
@@ -252,7 +253,7 @@ mod bytebuf {
|
|||||||
fn visit_seq<V>(self, mut visitor: V) -> Result<ByteBuf, V::Error>
|
fn visit_seq<V>(self, mut visitor: V) -> Result<ByteBuf, V::Error>
|
||||||
where V: de::SeqVisitor,
|
where V: de::SeqVisitor,
|
||||||
{
|
{
|
||||||
let (len, _) = visitor.size_hint();
|
let len = cmp::min(visitor.size_hint().0, 4096);
|
||||||
let mut values = Vec::with_capacity(len);
|
let mut values = Vec::with_capacity(len);
|
||||||
|
|
||||||
while let Some(value) = try!(visitor.visit()) {
|
while let Some(value) = try!(visitor.visit()) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#![doc(hidden)]
|
#![doc(hidden)]
|
||||||
|
|
||||||
|
use core::cmp;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
@@ -215,7 +216,7 @@ impl<E> Visitor for ContentVisitor<E> {
|
|||||||
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||||
where V: SeqVisitor
|
where V: SeqVisitor
|
||||||
{
|
{
|
||||||
let mut vec = Vec::with_capacity(visitor.size_hint().0);
|
let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096));
|
||||||
while let Some(e) = try!(visitor.visit()) {
|
while let Some(e) = try!(visitor.visit()) {
|
||||||
vec.push(e);
|
vec.push(e);
|
||||||
}
|
}
|
||||||
@@ -225,7 +226,7 @@ impl<E> Visitor for ContentVisitor<E> {
|
|||||||
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||||
where V: MapVisitor
|
where V: MapVisitor
|
||||||
{
|
{
|
||||||
let mut vec = Vec::with_capacity(visitor.size_hint().0);
|
let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096));
|
||||||
while let Some(kv) = try!(visitor.visit()) {
|
while let Some(kv) = try!(visitor.visit()) {
|
||||||
vec.push(kv);
|
vec.push(kv);
|
||||||
}
|
}
|
||||||
@@ -489,7 +490,7 @@ impl<T, E> Visitor for TaggedContentVisitor<T, E>
|
|||||||
where V: MapVisitor
|
where V: MapVisitor
|
||||||
{
|
{
|
||||||
let mut tag = None;
|
let mut tag = None;
|
||||||
let mut vec = Vec::with_capacity(visitor.size_hint().0);
|
let mut vec = Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096));
|
||||||
while let Some(k) = try!(visitor.visit_key_seed(TagOrContentVisitor::new(self.tag_name))) {
|
while let Some(k) = try!(visitor.visit_key_seed(TagOrContentVisitor::new(self.tag_name))) {
|
||||||
match k {
|
match k {
|
||||||
TagOrContent::Tag => {
|
TagOrContent::Tag => {
|
||||||
|
|||||||
Reference in New Issue
Block a user