Exploit databaseDownload repository ZIP
GH-bb869ee2ecd06b833875f4f79893e7d7
yavuzsemih/brotli-secfix
Sources for CVE-2026-111497
61 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files3
yavuzsemih/brotli-secfixRevision b8773fc14e90
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
scripts/prepare_quilt_patch.py
Python · 4,963 bytes#!/usr/bin/env python3
"""Fail-closed conversion of an upstream Git patch to an Ubuntu quilt patch.
Requires an unmodified Brotli v1.1.0 upstream decoder pair and validates the
result byte-for-byte against the two upstream post-fix Git blobs.
"""
import argparse
import difflib
import hashlib
import os
import pathlib
import subprocess
import sys
import tempfile
COMMIT = "da9806362874b9bd4b552a3af360b5d6347beb12"
PATCH_SHA256 = "3c22a81fd189a8ef27b4001e10470f3a8753a2e2e40c35a483f1a700a144cbec"
BLOBS = {
"c/dec/decode.c": (
"220c7e85c6331bff7a0a44c55f951823b143fd56",
"2b45765563464d49c91ac480d6ba1e868d97f113",
),
"c/include/brotli/decode.h": (
"af1aa23f60d7cfdd1c4e9cd9a8284c88414d2167",
"18ca1482d759df6edee556b6f9c02ab01246865f",
),
}
def git_blob_hash(data: bytes) -> str:
return hashlib.sha1(b"blob " + str(len(data)).encode() + b"\0" + data).hexdigest()
def assert_valid_patch(patch: pathlib.Path) -> None:
digest = hashlib.sha256(patch.read_bytes()).hexdigest()
if digest != PATCH_SHA256:
raise ValueError(f"untrusted or modified upstream patch: {digest}")
def make_patch(source: pathlib.Path, upstream_patch: pathlib.Path) -> str:
assert_valid_patch(upstream_patch)
with tempfile.TemporaryDirectory(prefix="brotli-patch-verify-") as tmp:
shadow = pathlib.Path(tmp)
originals = {}
for relative, (before_hash, _) in BLOBS.items():
raw = (source / relative).read_bytes()
digest = git_blob_hash(raw)
if digest != before_hash:
raise ValueError(f"baseline mismatch for {relative}: {digest}; expected {before_hash}")
originals[relative] = raw
out = shadow / relative
out.parent.mkdir(parents=True, exist_ok=True)
out.write_bytes(raw)
# --ignore-space-change enables applying context to Ubuntu's whitespace;
# post-application hashes enforce exact equivalence with upstream.
subprocess.run(
["git", "apply", "--ignore-space-change", str(upstream_patch.resolve())],
cwd=shadow, check=True,
)
sections = [
"Description: Backport upstream Brotli decoder block-switch validation fix.\n",
f"Origin: upstream, https://github.com/google/brotli/commit/{COMMIT}\n",
"Bug: https://ubuntu.com/security/CVE-2026-111497\n",
"Forwarded: not-needed\n",
"Last-Update: 2026-10-24\n",
"\n",
]
for relative, (_, after_hash) in BLOBS.items():
new = (shadow / relative).read_bytes()
digest = git_blob_hash(new)
if digest != after_hash:
raise ValueError(f"patched output mismatch for {relative}: {digest}; expected {after_hash}")
old = originals[relative]
for buf in (old, new):
if not buf.endswith(b"\n"):
raise ValueError(f"unexpected missing newline in {relative}")
a = old.decode("utf-8").splitlines(keepends=True)
b = new.decode("utf-8").splitlines(keepends=True)
block = list(difflib.unified_diff(a, b, fromfile="a/" + relative,
tofile="b/" + relative, n=3))
if not block:
raise ValueError(f"no changes in {relative}")
sections.extend(block)
return "".join(sections)
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--source", type=pathlib.Path, required=True)
parser.add_argument("--upstream-patch", type=pathlib.Path, required=True)
parser.add_argument("--output", type=pathlib.Path, required=True)
args = parser.parse_args()
try:
content = make_patch(args.source, args.upstream_patch)
if args.output.exists():
raise ValueError(f"refusing to overwrite existing output: {args.output}")
args.output.parent.mkdir(parents=True, exist_ok=True)
# Atomic publication avoids leaving a truncated patch after an interrupted write.
with tempfile.NamedTemporaryFile(
mode="w", encoding="utf-8", newline="\n", dir=args.output.parent,
prefix=".pending-patch-", delete=False
) as pending:
pending.write(content)
pending_path = pathlib.Path(pending.name)
try:
# Atomic create-if-absent; never overwrite an existing reviewed patch.
os.link(pending_path, args.output)
finally:
pending_path.unlink(missing_ok=True)
print(f"Verified {len(BLOBS)} patched files against upstream {COMMIT}")
print(f"Created quilt patch: {args.output}")
return 0
except (ValueError, OSError, subprocess.CalledProcessError) as exc:
print(f"STOP: {exc}", file=sys.stderr)
return 1
if __name__ == "__main__":
raise SystemExit(main())