lix/src
jade 917c9bdee7 language: cleanly ban integer overflows
This also bans various sneaking of negative numbers from the language
into unsuspecting builtins as was exposed while auditing the
consequences of changing the Nix language integer type to a newtype.

It's unlikely that this change comprehensively ensures correctness when
passing integers out of the Nix language and we should probably add a
checked-narrowing function or something similar, but that's out of scope
for the immediate change.

During the development of this I found a few fun facts about the
language:
- You could overflow integers by converting from unsigned JSON values.
- You could overflow unsigned integers by converting negative numbers
  into them when going into Nix config, into fetchTree, and into flake
  inputs.

  The flake inputs and Nix config cannot actually be tested properly
  since they both ban thunks, however, we put in checks anyway because
  it's possible these could somehow be used to do such shenanigans some
  other way.

Note that Lix has banned Nix language integer overflows since the very
first public beta, but threw a SIGILL about them because we run with
-fsanitize=signed-overflow -fsanitize-undefined-trap-on-error in
production builds. Since the Nix language uses signed integers, overflow
was simply undefined behaviour, and since we defined that to trap, it
did.

Trapping on it was a bad UX, but we didn't even entirely notice
that we had done this at all until it was reported as a bug a couple of
months later (which is, to be fair, that flag working as intended), and
it's got enough production time that, aside from code that is IMHO buggy
(and which is, in any case, not in nixpkgs) such as
lix-project/lix#445, we don't think
anyone doing anything reasonable actually depends on wrapping overflow.

Even for weird use cases such as doing funny bit crimes, it doesn't make
sense IMO to have wrapping behaviour, since two's complement arithmetic
overflow behaviour is so *aggressively* not what you want for *any* kind
of mathematics/algorithms. The Nix language exists for package
management, a domain where bit crimes are already only dubiously in
scope to begin with, and it makes a lot more sense for that domain for
the integers to never lose precision, either by throwing errors if they
would, or by being arbitrary-precision.

This change will be ported to CppNix as well, to maintain language
consistency.

Fixes: lix-project/lix#423

Change-Id: I51f253840c4af2ea5422b8a420aa5fafbf8fae75
2024-07-13 00:59:33 +02:00
..
build-remote build-remote: truncate+hash store URI used in lockfile paths 2024-05-31 12:18:24 +00:00
libcmd language: cleanly ban integer overflows 2024-07-13 00:59:33 +02:00
libexpr language: cleanly ban integer overflows 2024-07-13 00:59:33 +02:00
libfetchers libutil: return sources from runProgram2 2024-07-06 12:36:36 +02:00
libmain libmain: clear display attributes in the multiline progress bar 2024-07-08 19:08:23 +02:00
libstore language: cleanly ban integer overflows 2024-07-13 00:59:33 +02:00
libutil libutil: add checked arithmetic tools 2024-07-13 00:56:37 +02:00
nix libutil: turn HashModuloSink into a free function 2024-07-06 12:36:37 +02:00
nix-build tree-wide: unify progress bar inactive and paused states 2024-07-01 18:19:34 +02:00
nix-channel util.{hh,cc}: Split out users.{hh,cc} 2024-05-29 11:01:34 +02:00
nix-collect-garbage Fix dry-run flag for nix-collect-garbage 2024-07-09 13:55:05 +00:00
nix-copy-closure Merge pull request #9277 from keszybz/file-permissions 2024-03-04 05:26:17 +01:00
nix-env Use std::strong_ordering for version comparison 2024-07-12 16:48:28 +02:00
nix-instantiate libexpr: pass Exprs as references, not pointers 2024-06-17 19:46:44 +00:00
nix-store libstore: convert dumpPath to a generator 2024-07-05 22:28:16 +00:00
pch build-time: remove 20% more by PCH'ing C++ stdlib 2024-05-30 21:54:21 +00:00
resolve-system-dependencies remove the autoconf+Make buildsystem 2024-05-07 17:04:30 -06:00
lix-base.pc.in packaging: rename nixexpr -> lixexpr and so on 2024-05-23 16:45:23 -06:00
meson.build meson: implement functional tests 2024-03-27 18:37:50 -06:00