gh-148286: Fail when new UB is found by CI UBSan (#148168) · python/cpython@ade914b

GitHub

Original file line numberDiff line numberDiff line change@@ -61,7 +61,7 @@ jobs:

6161 || ''

6262 }}.txt handle_segv=0" >> "$GITHUB_ENV"

6363 else

64- echo "UBSAN_OPTIONS=${SAN_LOG_OPTION}" >> "$GITHUB_ENV"

64+ echo "UBSAN_OPTIONS=${SAN_LOG_OPTION} halt_on_error=1 suppressions=${GITHUB_WORKSPACE}/Tools/ubsan/suppressions.txt" >> "$GITHUB_ENV"

6565 fi

6666 echo "CC=clang" >> "$GITHUB_ENV"

6767 echo "CXX=clang++" >> "$GITHUB_ENV"

@@ -75,18 +75,21 @@ jobs:

7575 ${{

7676 inputs.sanitizer == 'TSan'

7777 && '--with-thread-sanitizer'

78- || '--with-undefined-behavior-sanitizer'

78+ || '--with-undefined-behavior-sanitizer --with-strict-overflow'

7979 }}

8080 --with-pydebug

8181 ${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}

8282 - name: Build CPython

8383run: make -j4

8484 - name: Display build info

8585run: make pythoninfo

86+# test_{capi,faulthandler} are skipped under UBSan because

87+# they raise signals that UBSan with halt_on_error=1 intercepts.

8688 - name: Tests

8789run: >-

8890 ./python -m test

8991 ${{ inputs.sanitizer == 'TSan' && '--tsan' || '' }}

92+ ${{ inputs.sanitizer == 'UBSan' && '-x test_capi -x test_faulthandler' || '' }}

9093 -j4

9194 - name: Parallel tests

9295if: >-

Original file line numberDiff line numberDiff line change@@ -0,0 +1,28 @@

1+# This file contains suppressions for the UndefinedBehaviour sanitizer.

2+#

3+# Reference: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#runtime-suppressions

4+#

5+# When adding a suppression, include a comment referencing a GitHub issue

6+# that describes how to reproduce the race and includes the relevant UBSan

7+# output.

8+9+# Objects/object.c:97:5: runtime error: member access within null pointer of type 'PyThreadState' (aka 'struct _ts')

10+null:Objects/object.c

11+12+# Objects/memoryobject.c:3032:15: runtime error: load of value 2, which is not a valid value for type 'bool'

13+bool:Objects/memoryobject.c

14+15+# Modules/_ctypes/cfield.c:644:1: runtime error: left shift of 1 by 63 places cannot be represented in type 'int64_t' (aka 'long')

16+shift-base:Modules/_ctypes/cfield.c

17+18+# Modules/_ctypes/cfield.c:640:1: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'

19+signed-integer-overflow:Modules/_ctypes/cfield.c

20+21+# Modules/_zstd/decompressor.c:598:56: runtime error: applying non-zero offset 18446744073709551615 to null pointer

22+pointer-overflow:Modules/_zstd/decompressor.c

23+24+# Modules/_io/stringio.c:350:24: runtime error: addition of unsigned offset to 0x7fd01ec25850 overflowed to 0x7fd01ec2584c

25+pointer-overflow:Modules/_io/stringio.c

26+27+# Objects/bytesobject.c:1190:25: runtime error: applying zero offset to null pointer

28+pointer-overflow:Objects/bytesobject.c