Subject: bug#42660: emacs-27.1-rc1 and UBsan findings

From: Lars Ingebrigtsen <[email-masked]>
Date: Mon, 10 Aug 2020 01:00:40 +0200

Jeffrey Walton <[email-masked]> writes:

> $ cat emacs-27.1/test/lisp/international/ccl-tests.log
> Running 7 tests (2020-08-01 16:28:12-0400, selector `(not (or (tag
> :expensive-test) (tag :unstable)))')
>    passed  1/7  ccl-compile-midi (0.000181 sec)
>    passed  2/7  ccl-compile-pgg (0.000093 sec)
>    passed  3/7  ccl-dump-midi (0.005956 sec)
>    passed  4/7  ccl-dump-pgg (0.000111 sec)
> Package pgg-def is deprecated
> Package pgg-parse is deprecated
> Package pgg is deprecated
> ccl.c:1146:29: runtime error: left shift of 1246883553 by 1 places
> cannot be represented in type 'int'

I get the same, basically:

Running 7 tests (2020-08-10 00:55:35+0200, selector `(not (tag :unstable))')
   passed  1/7  ccl-compile-midi (0.000614 sec)
   passed  2/7  ccl-compile-pgg (0.000371 sec)
   passed  3/7  ccl-dump-midi (0.001032 sec)
   passed  4/7  ccl-dump-pgg (0.000531 sec)
Package pgg-def is deprecated
Package pgg-parse is deprecated
Package pgg is deprecated
ccl.c:1153:29: runtime error: left shift of 1239426054 by 1 places cannot be represented in type 'int'
make[1]: *** [Makefile:183: lisp/international/ccl-tests.log] Error 1

This is the test that fails:

(ert-deftest pgg-parse-crc24 ()
  ;; Compiler
  (require 'pgg)
  (should (equal pgg-parse-crc24 prog-pgg-code))
  ;; Interpreter
  (should (equal (pgg-parse-crc24-string "foo") (concat [#x4f #xc2 #x55])))
  (should (equal (pgg-parse-crc24-string "bar") (concat [#x51 #xd9 #x53])))
  (should (equal (pgg-parse-crc24-string "baz") (concat [#xf0 #x58 #x6a]))))

All three of those pgg-parse calls make Emacs signal a runtime error
with this checking turned on.

So this is with:

CFLAGS="-fsanitize=undefined -fno-sanitize-recover=all" ./configure && make

Now, pgg is obsolete, so that's a test that probably should go away.
So is this a bug?  The thing that fails is this:

	    case CCL_LSH: reg[rrr] <<= i; break;

So it's doing a left shift on a too-high number...  which is something
that pgg does, but since that's obsolete, do we care?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no