-
Notifications
You must be signed in to change notification settings - Fork 79
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
make zero-sized value counting more fine grained #516
Conversation
Benchmark for 92f94e6Click to view benchmark
|
fn dec_zero_sized_value(&mut self) -> Result<()> { | ||
//eprintln!("{}", self.zero_sized_values); | ||
if self.zero_sized_values == 0 { | ||
return Err(Error::msg("Too many zero sized values")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Err(Error::msg("Too many zero sized values")); | |
return Err(Error::msg("Too many zero sized values")); |
return Err(Error::msg("Too many zero sized values")); | |
return Err(Error::msg("Too many zero-sized values")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me. Nice to have some examples too.
}), | ||
_ => false, | ||
fn dec_zero_sized_value(&mut self) -> Result<()> { | ||
//eprintln!("{}", self.zero_sized_values); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this comment be dropped?
spec/Candid.md
Outdated
@@ -1255,7 +1255,7 @@ M(id(v*) : principal) = i8(1) M(v* : vec nat8) | |||
|
|||
Note: | |||
|
|||
* Since `null`, `reserved`, `record {}`, and records of such values, take no space, to prevent unbounded sized message, we limit the total vector length of such zero-sized values in a messagev (on the wire) to be 2,000,000 elements. For example, if a message contains two vectors, one at type `vec null` and one at type `vec record {}`, then the length of both vectors combined cannot exceed 2,000,000 elements. | |||
* Since `null`, `reserved` and `record {}` take no space, to prevent unbounded sized message, we limit the total number of such zero-sized values in a message (on the wire) to be 2,000,000 elements. For example, a value of type `record { null; reserved; record { record {} } }` contains 3 zero-sized values; a value of type `vec opt record { null; null }` with length 100 contains at most 200 zero-sized values (it is 200 when the vector contains no `null` values); if a message contains two vectors, one at type `vec null` and one at type `vec record {}`, then the length of both vectors combined cannot exceed 2,000,000 elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a value of type
record { null; reserved; record { record {} } }
contains 3 zero-sized values
Could you please list the zero-sized values explicitly? I believe to have counter 4:
null
reserved
record {}
record { record {} }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in fact also the entire record { null; reserved; record { record {} } }
is a 5th zero-sized value there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try to rephrase the spec. We only count the occurrences of null
, reserved
and record {}
to simulate the effect that if these values were not zero sized. record { record {} }
would not be zero sized, if record {}
weren't zero sized.
@@ -337,16 +334,13 @@ impl<'de> Deserializer<'de> { | |||
} | |||
Ok(()) | |||
} | |||
fn is_zero_sized_type(&self, t: &Type) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptually, we should check this condition for every (nested) value and limit all such (nested) zero-sized values at 2M in total.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above. That would be overcounting, e.g., record { null; null }
would be counted as 3 instead of 2.
Benchmark for 029bbc4Click to view benchmark
|
Update spec to limit the number of zero-sized values in a message, instead of the sum length of
vec {zero-sized value}
.