From 0376533c04e07784b69590daab5684ac51730c11 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Wed, 5 Apr 2023 20:41:47 +0300 Subject: [PATCH 1/2] cicd: add a test job with enabled UBSAN --- .github/workflows/build.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 27b31085..cf3628a1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -169,3 +169,34 @@ jobs: lib/binding_web/tree-sitter.wasm if-no-files-found: error retention-days: 7 + + check_undefined_behaviour: + name: Undefined behaviour checks + runs-on: ubuntu-latest + env: + TREE_SITTER: ${{ github.workspace }}/target/release/tree-sitter + steps: + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Install UBSAN library + run: sudo apt-get install -y libubsan1 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Build CLI + run: cargo build --release + + - name: Fetch fixtures + run: script/fetch-fixtures + + - name: Generate fixtures + run: script/generate-fixtures + + - name: Run main tests with undefined behaviour sanitizer (UBSAN) + env: + UBSAN_OPTIONS: halt_on_error=1 + CFLAGS: -fsanitize=undefined + RUSTFLAGS: -lubsan + run: cargo test -- --test-threads 1 From 0d326824d25912ab0fb558e54980554111f71e64 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Thu, 6 Apr 2023 01:49:50 +0300 Subject: [PATCH 2/2] test: add a reproducing test for #2162 --- cli/src/tests/github_issue_test.rs | 16 ++++++++++++++++ cli/src/tests/mod.rs | 1 + 2 files changed, 17 insertions(+) create mode 100644 cli/src/tests/github_issue_test.rs diff --git a/cli/src/tests/github_issue_test.rs b/cli/src/tests/github_issue_test.rs new file mode 100644 index 00000000..42fe3e9a --- /dev/null +++ b/cli/src/tests/github_issue_test.rs @@ -0,0 +1,16 @@ +// Tests in this mod need be executed with enabled UBSAN library: +// ``` +// UBSAN_OPTIONS="halt_on_error=1" \ +// CFLAGS="-fsanitize=undefined" \ +// RUSTFLAGS="-lubsan" \ +// cargo test --target $(rustc -vV | sed -nr 's/^host: //p') -- --test-threads 1 +// ``` + +use crate::tests::helpers::fixtures::get_language; +use tree_sitter::Query; + +#[test] +fn issue_2162_out_of_bound() { + let language = get_language("java"); + assert!(Query::new(language, "(package_declaration _ (_) @name _)").is_ok()); +} diff --git a/cli/src/tests/mod.rs b/cli/src/tests/mod.rs index 1b804450..03a588b9 100644 --- a/cli/src/tests/mod.rs +++ b/cli/src/tests/mod.rs @@ -1,4 +1,5 @@ mod corpus_test; +mod github_issue_test; mod helpers; mod highlight_test; mod node_test;