Skip to content

Commit 2f33862

Browse files
committed
libcss: add oss-fuzz support for libcss
Libcss is a lightweight, open-source CSS parsing and selection library from the NetSurf project. It processes CSS inputs, handling parsing, preprocessing (e.g., ::cue, ID selectors), and style selection via libcss APIs. Fuzzing libcss is critical due to its exposure to untrusted CSS inputs in multimedia pipelines, where malformed stylesheets could trigger crashes, memory corruption, or undefined behavior. Adding this fuzzer to OSS-Fuzz enhances security by testing the parser against random inputs, covering key functions like css_stylesheet_append_data and css_select_style, and detecting potential vulnerabilities in real-world use cases. The fuzzer, css_parse_fuzzer.cc, targets the core parsing logic from gstcssparse.c and uses Meson for building libcss and its submodules (libwapcaplet, libparserutils).
1 parent eb47f56 commit 2f33862

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

projects/libcss/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
################################################################################
16+
17+
FROM gcr.io/oss-fuzz-base/base-builder
18+
19+
RUN apt-get update && apt-get install -y python3-pip ninja-build
20+
RUN pip3 install meson
21+
RUN git clone --depth 1 https://gitlab.collabora.com/libcss/libcss.git libcss
22+
RUN git clone --depth 1 https://gitlab.collabora.com/libcss/libcss-tests.git libcss-tests
23+
WORKDIR libcss
24+
COPY build.sh $SRC/
25+
26+

projects/libcss/build.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash -eu
2+
# Copyright 2025 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
################################################################################
17+
18+
# Build libcss and dependencies
19+
cd $SRC/libcss
20+
cd build
21+
meson setup .. --default-library=static
22+
ninja -j$(nproc)
23+
ninja install
24+
cd ../..
25+
26+
27+
# Set executable permissions for fuzzer build scripts
28+
chmod +x $SRC/libcss/test/fuzzers/build_google_oss_fuzzers.sh
29+
chmod +x $SRC/libcss/test/fuzzers/build_seed_corpus.sh
30+
31+
# Build fuzzers and seed corpus
32+
$SRC/libcss/test/fuzzers/build_google_oss_fuzzers.sh
33+
$SRC/libcss/test/fuzzers/build_seed_corpus.sh

projects/libcss/project.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
homepage: "https://gitlab.collabora.com/libcss"
2+
primary_contact: "[email protected]"
3+
language: c
4+
fuzzing_engines:
5+
- libfuzzer
6+
- afl
7+
- honggfuzz
8+
sanitizers:
9+
- address
10+
- memory
11+
- undefined
12+
main_repo: 'https://gitlab.collabora.com/libcss/libcss.git'

0 commit comments

Comments
 (0)