Fixed panic on math with large durations (#3669)

* Output error when ls into a file without permission

* math sqrt

* added test to check fails when ls into prohibited dir

* fix lint

* math sqrt with tests and doc

* trigger wasm build

* Update filesystem_shell.rs

* Fix Running echo .. starts printing integers forever

* Fixed panic on operations with very large durations

Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
This commit is contained in:
Luccas Mateus 2021-06-23 00:44:14 -03:00 committed by GitHub
parent 55cab9eb4f
commit 2b021472d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -235,6 +235,18 @@ fn duration_math_with_negative() {
assert_eq!(actual.out, "-6day");
}
#[test]
fn duration_math_shell_error_on_big_numbers() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
(date now) + 100000000000000day
"#
));
assert!(actual.err.contains("Duration overflow"));
}
#[test]
fn compound_comparison() {
let actual = nu!(

View File

@ -289,7 +289,17 @@ impl Primitive {
.expect("Internal error: conversion from u32 failed"),
);
let secs = match secs.to_i64() {
Some(secs) => secs,
//The duration crate doesnt accept seconds bigger than i64::MAX / 1000
Some(secs) => match secs.checked_mul(1000) {
Some(_) => secs,
None => {
return Err(ShellError::labeled_error(
"Internal duration conversion overflow.",
"duration overflow",
span,
))
}
},
None => {
return Err(ShellError::labeled_error(
"Internal duration conversion overflow.",