mirror of
https://github.com/NixOS/nix
synced 2025-07-08 06:53:54 +02:00
Merge pull request #11188 from lf-/jade/kill-int-overflow
Ban integer overflow in the Nix language
This commit is contained in:
commit
18485d2d53
40 changed files with 707 additions and 81 deletions
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while calling the 'fetchTree' builtin
|
||||
at /pwd/lang/eval-fail-fetchTree-negative.nix:1:1:
|
||||
1| builtins.fetchTree {
|
||||
| ^
|
||||
2| type = "file";
|
||||
|
||||
error: negative value given for fetchTree attr owner: -1
|
5
tests/functional/lang/eval-fail-fetchTree-negative.nix
Normal file
5
tests/functional/lang/eval-fail-fetchTree-negative.nix
Normal file
|
@ -0,0 +1,5 @@
|
|||
builtins.fetchTree {
|
||||
type = "file";
|
||||
url = "file://eval-fail-fetchTree-negative.nix";
|
||||
owner = -1;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
error:
|
||||
… while calling the 'seq' builtin
|
||||
at /pwd/lang/eval-fail-flake-ref-to-string-negative-integer.nix:1:16:
|
||||
1| let n = -1; in builtins.seq n (builtins.flakeRefToString {
|
||||
| ^
|
||||
2| type = "github";
|
||||
|
||||
… while calling the 'flakeRefToString' builtin
|
||||
at /pwd/lang/eval-fail-flake-ref-to-string-negative-integer.nix:1:32:
|
||||
1| let n = -1; in builtins.seq n (builtins.flakeRefToString {
|
||||
| ^
|
||||
2| type = "github";
|
||||
|
||||
error: negative value given for flake ref attr repo: -1
|
|
@ -0,0 +1,7 @@
|
|||
let n = -1; in builtins.seq n (builtins.flakeRefToString {
|
||||
type = "github";
|
||||
owner = "NixOS";
|
||||
repo = n;
|
||||
ref = "23.05";
|
||||
dir = "lib";
|
||||
})
|
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while calling the 'fromJSON' builtin
|
||||
at /pwd/lang/eval-fail-fromJSON-overflowing.nix:1:1:
|
||||
1| builtins.fromJSON ''{"attr": 18446744073709551615}''
|
||||
| ^
|
||||
2|
|
||||
|
||||
error: unsigned json number 18446744073709551615 outside of Nix integer range
|
1
tests/functional/lang/eval-fail-fromJSON-overflowing.nix
Normal file
1
tests/functional/lang/eval-fail-fromJSON-overflowing.nix
Normal file
|
@ -0,0 +1 @@
|
|||
builtins.fromJSON ''{"attr": 18446744073709551615}''
|
6
tests/functional/lang/eval-fail-overflowing-add.err.exp
Normal file
6
tests/functional/lang/eval-fail-overflowing-add.err.exp
Normal file
|
@ -0,0 +1,6 @@
|
|||
error: integer overflow in adding 9223372036854775807 + 1
|
||||
at /pwd/lang/eval-fail-overflowing-add.nix:4:8:
|
||||
3| b = 1;
|
||||
4| in a + b
|
||||
| ^
|
||||
5|
|
4
tests/functional/lang/eval-fail-overflowing-add.nix
Normal file
4
tests/functional/lang/eval-fail-overflowing-add.nix
Normal file
|
@ -0,0 +1,4 @@
|
|||
let
|
||||
a = 9223372036854775807;
|
||||
b = 1;
|
||||
in a + b
|
23
tests/functional/lang/eval-fail-overflowing-div.err.exp
Normal file
23
tests/functional/lang/eval-fail-overflowing-div.err.exp
Normal file
|
@ -0,0 +1,23 @@
|
|||
error:
|
||||
… while calling the 'seq' builtin
|
||||
at /pwd/lang/eval-fail-overflowing-div.nix:7:4:
|
||||
6| b = -1;
|
||||
7| in builtins.seq intMin (builtins.seq b (intMin / b))
|
||||
| ^
|
||||
8|
|
||||
|
||||
… while calling the 'seq' builtin
|
||||
at /pwd/lang/eval-fail-overflowing-div.nix:7:25:
|
||||
6| b = -1;
|
||||
7| in builtins.seq intMin (builtins.seq b (intMin / b))
|
||||
| ^
|
||||
8|
|
||||
|
||||
… while calling the 'div' builtin
|
||||
at /pwd/lang/eval-fail-overflowing-div.nix:7:48:
|
||||
6| b = -1;
|
||||
7| in builtins.seq intMin (builtins.seq b (intMin / b))
|
||||
| ^
|
||||
8|
|
||||
|
||||
error: integer overflow in dividing -9223372036854775808 / -1
|
7
tests/functional/lang/eval-fail-overflowing-div.nix
Normal file
7
tests/functional/lang/eval-fail-overflowing-div.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
let
|
||||
# lol, this has to be written as an expression like this because negative
|
||||
# numbers use unary negation rather than parsing directly, and 2**63 is out
|
||||
# of range
|
||||
intMin = -9223372036854775807 - 1;
|
||||
b = -1;
|
||||
in builtins.seq intMin (builtins.seq b (intMin / b))
|
16
tests/functional/lang/eval-fail-overflowing-mul.err.exp
Normal file
16
tests/functional/lang/eval-fail-overflowing-mul.err.exp
Normal file
|
@ -0,0 +1,16 @@
|
|||
error:
|
||||
… while calling the 'mul' builtin
|
||||
at /pwd/lang/eval-fail-overflowing-mul.nix:3:10:
|
||||
2| a = 4294967297;
|
||||
3| in a * a * a
|
||||
| ^
|
||||
4|
|
||||
|
||||
… while calling the 'mul' builtin
|
||||
at /pwd/lang/eval-fail-overflowing-mul.nix:3:6:
|
||||
2| a = 4294967297;
|
||||
3| in a * a * a
|
||||
| ^
|
||||
4|
|
||||
|
||||
error: integer overflow in multiplying 4294967297 * 4294967297
|
3
tests/functional/lang/eval-fail-overflowing-mul.nix
Normal file
3
tests/functional/lang/eval-fail-overflowing-mul.nix
Normal file
|
@ -0,0 +1,3 @@
|
|||
let
|
||||
a = 4294967297;
|
||||
in a * a * a
|
9
tests/functional/lang/eval-fail-overflowing-sub.err.exp
Normal file
9
tests/functional/lang/eval-fail-overflowing-sub.err.exp
Normal file
|
@ -0,0 +1,9 @@
|
|||
error:
|
||||
… while calling the 'sub' builtin
|
||||
at /pwd/lang/eval-fail-overflowing-sub.nix:4:6:
|
||||
3| b = 2;
|
||||
4| in a - b
|
||||
| ^
|
||||
5|
|
||||
|
||||
error: integer overflow in subtracting -9223372036854775807 - 2
|
4
tests/functional/lang/eval-fail-overflowing-sub.nix
Normal file
4
tests/functional/lang/eval-fail-overflowing-sub.nix
Normal file
|
@ -0,0 +1,4 @@
|
|||
let
|
||||
a = -9223372036854775807;
|
||||
b = 2;
|
||||
in a - b
|
Loading…
Add table
Add a link
Reference in a new issue