LibWeb: Reject invalid AnimationEffect duration string values

This commit is contained in:
Matthew Olsson 2024-05-28 03:32:00 -07:00 committed by Andreas Kling
parent 3e221fbb2d
commit 1965943026
Notes: sideshowbarker 2024-07-17 11:29:41 +09:00
3 changed files with 14 additions and 1 deletions

View File

@ -4,7 +4,9 @@ KeyframeEffect with NaN delay value: threw an exception
KeyframeEffect with infinite endDelay value: threw an exception
KeyframeEffect with NaN endDelay value: threw an exception
KeyframeEffect with NaN iterations: threw an exception
KeyframeEffect with non-"auto" string duration: threw an exception
KeyframeEffect with infinite options value: did not throw an exception
KeyframeEffect with finite options value: did not throw an exception
KeyframeEffect with infinite iterations: did not throw an exception
KeyframeEffect with infinite duration: did not throw an exception
KeyframeEffect with "auto" string duration: did not throw an exception

View File

@ -18,11 +18,13 @@
checkException('KeyframeEffect with infinite endDelay value', () => new KeyframeEffect(null, null, { endDelay: Infinity }));
checkException('KeyframeEffect with NaN endDelay value', () => new KeyframeEffect(null, null, { endDelay: NaN }));
checkException('KeyframeEffect with NaN iterations', () => new KeyframeEffect(null, null, { iterations: NaN }));
checkException('KeyframeEffect with non-"auto" string duration', () => new KeyframeEffect(null, null, { duration: 'abc' }))
// Test valid values
checkException('KeyframeEffect with infinite options value', () => new KeyframeEffect(null, null, Infinity));
checkException('KeyframeEffect with finite options value', () => new KeyframeEffect(null, null, 1234.5));
checkException('KeyframeEffect with infinite iterations', () => new KeyframeEffect(null, null, { iterations: Infinity }));
checkException('KeyframeEffect with infinite duration', () => new KeyframeEffect(null, null, { duration: Infinity }));
checkException('KeyframeEffect with "auto" string duration', () => new KeyframeEffect(null, null, { duration: 'auto' }))
});
</script>

View File

@ -140,7 +140,16 @@ WebIDL::ExceptionOr<void> AnimationEffect::update_timing(OptionalEffectTiming ti
// abort this procedure.
// Note: "auto", the only valid string value, is treated as 0.
auto& duration = timing.duration;
if (duration.has_value() && duration->has<double>() && (duration->get<double>() < 0.0 || isnan(duration->get<double>())))
auto has_valid_duration_value = [&] {
if (!duration.has_value())
return true;
if (duration->has<double>() && (duration->get<double>() < 0.0 || isnan(duration->get<double>())))
return false;
if (duration->has<String>() && (duration->get<String>() != "auto"))
return false;
return true;
}();
if (!has_valid_duration_value)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid duration value"sv };
// 4. If the easing member of input exists but cannot be parsed using the <easing-function> production