跳到正文
Skillpedia
测试8.6k · #12363

find-postgres-bug

它能做什么

这个技能利用调试版编译和自动化模糊测试,在 PostgreSQL 源代码检出目录中搜索崩溃漏洞。适合希望发现并报告真实缺陷的 PostgreSQL 开发者和贡献者。

适用场景

  • ✓你想在本地 PostgreSQL 源代码树中查找崩溃漏洞的时候。
  • ✓你需要调试版 PostgreSQL 来进行模糊测试的时候。
  • ✓你想获得最小复现案例,以及提交给社区的漏洞报告的时候。

技能链接

https://github.com/digoal/blog/blob/master/skills/find-postgres-bug/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/digoal/blog/blob/master/skills/find-postgres-bug/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请为我的 PostgreSQL 代码检出编译一个调试版本,进行模糊测试找崩溃,并为发现的问题制作最小测试用例。”

每周 5 个新技能,1 分钟读完。

工作原理

它构建一个严格的调试实例,运行模糊测试器直到服务器崩溃,读取崩溃核心转储,缩减输入,并检查是哪个提交引入了问题。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Find Postgres Bug

Overview

Crash-first bug-hunting pipeline for a local PostgreSQL source tree. The order matters and is the whole point:

poison the build  →  fuzz it  →  triage the core  →  minimise to an MRE
                  →  bisect the commit  →  report (do NOT self-patch)

The leverage is front-loaded. A poisoned build does ~90% of the work by turning latent bugs into immediate crashes; the fuzzer then finds inputs no human would hand-write. Reading commits by eye is a secondary, targeted probe — used to aim the fuzzer, not as the primary search.

Source layout assumed: the standard PG tree (src/backend/, src/include/, contrib/, src/test/, …) at $PG_SRC_DIR.

Three hard rules:

  1. The skill never auto-stops the instance. Run scripts/stop_pg.sh explicitly when done.
  2. Never write a patch. The deliverable is an MRE + backtrace + bisect result, posted upstream. A drive-by fix from someone who just met the code is worth less than a clean reproducer.
  3. A finding only counts if it crashes at HEAD, with the tree exactly as committed. Never revert a fix (or commit a staged revert) to make something crash and call it a bug — that just re-creates an already-fixed bug and is worthless. Before investing in any candidate, run the pre-flight in Step 0. See references/already_fixed.md.

Quick start

export PG_SRC_DIR=/path/to/postgres

# 1. POISON: configure+build+initdb+start with cassert, cache-discard,
#    -O0 -ggdb3, core dumps enabled. The 90% lever.
./scripts/build_and_start_pg.sh

# 2. SEED + FUZZ: load some tables, then let sqlsmith run (overnight is best)
psql -h /tmp -p 55432 -d postgres -f your_schema.sql   # populate the catalog
./scripts/fuzz_sqlsmith.sh 3600 postgres               # 1h; use 28800 overnight

# 3. TRIAGE: a crash leaves a core under $PGDATA
./scripts/triage_core.sh /path/to/$PGDATA/core.NNNN

# 4. MINIMISE: cut the failing query down, confirm it crashes on demand
$EDITOR repro/mybug.sql
./scripts/run_repro.sh repro/mybug.sql mybug          # "SERVER IS DOWN" = good

# 5. BISECT: find the commit that introduced it
./scripts/bisect_run.sh repro/mybug.sql REL_17_STABLE HEAD

# 6. REPORT: render markdown for pgsql-bugs (no patch)
$EDITOR /tmp/bug.yaml
./scripts/gen_bug_report.sh /tmp/bug.yaml

# when finished:
./scripts/stop_pg.sh

If a real crash surfaces, the markdown is ready for [pgsql-bugs]. If the fuzzer runs clean, broaden the seed schema / run longer / switch branch.


Workflow

Each step has a success criterion to verify before moving on.

Step 0 — Pre-flight: clean tree & live-at-HEAD gate (do this first)

Before building or investing in any candidate, rule out the two biggest time-wasters: a dirty working tree, and a "bug" that HEAD already fixed.

cd "$PG_SRC_DIR"
git status --short            # any M/MM/A? the tree is NOT as-committed
git stash list               # stashed reverts hide here too
  • Dirty tree → stop and ask. Uncommitted edits (especially a staged revert of a fix) mean you are no longer testing HEAD. A git commit could re-introduce a fixed bug. Surface this to the user and do not build on top of it. Never git commit, git checkout, git restore, or git stash away the user's changes without explicit permission.
  • Always build and test the tree exactly as committed. Do not revert a fix to "reproduce" a bug. If you ever need to confirm a fix works, that is a fix-verification task, not a bug find — label it as such and do not report it as a new bug.

When the target is a specific commit (the user said "test this commit" or you picked one in Step 6), check it is not already superseded:

./scripts/check_already_fixed.sh <hash>   # is it in HEAD? any later "Fix"/revert touching the same files?

Success: git status is clean (or the user has explicitly accepted a dirty tree), and the candidate commit is confirmed not already fixed or reverted upstream. Only then proceed to Step 1. Details and edge cases: references/already_fixed.md.

Step 1 — Poison the build & start (the 90% lever)

export PG_SRC_DIR=/path/to/postgres
./scripts/build_and_start_pg.sh

Runs ./configure --enable-debug --enable-cassert --enable-debug-symbols --enable-tap-tests with CFLAGS="-O0 -ggdb3", auto-detects the cache-poison mechanism by **grepping the tree

常见问题

它会替我修复漏洞吗?

不会。技能要求不编写补丁,它的输出是复现案例和报告。

什么样的发现才算真实?

只有在当前代码树上按提交的原样就能稳定崩溃,才算真实发现。

测试服务器会自动停止吗?

不会,你完成后需要自己运行停止脚本。

详情

作者的原始描述

Find latent bugs in a local PostgreSQL source tree (REL_xx_STABLE branch or HEAD) the way a core hacker does: build a heavily-poisoned debug instance (cassert + cache-discard + -O0/-ggdb3 + core dumps), fuzz it (sqlsmith) until the backend crashes, triage the core into a minimal reproducer (MRE), git-bisect the introducing commit, and render a community-style pgsql-bugs markdown report. The instance never auto-shuts-down. Use when the user says "find a bug in postgres", "fuzz postgres", "hunt for a crash", "test a recent commit", "write a repro", "bisect this crash", "把 PG 跑起来找 bug", "fuzz 一下

repo: digoal/blog

热度

GitHub 星标
8.6k
排名
#12363
许可证
GPL-2.0
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能