Skip to content

A table name glued to a multi-line column list no longer crashes the Postgres reader - #15

Merged
avison9 merged 1 commit into
mainfrom
fix/postgres-glued-create-table
Sep 25, 2026
Merged

avison9 merged 1 commit into
mainfrom
fix/postgres-glued-create-table

Conversation

@avison9

@avison9 avison9 commented Sep 25, 2026

Copy link
Copy Markdown
Owner

What it changes

CREATE TABLE IF NOT EXISTS reactions( with the column list starting on the next line made cdclint panic:

panic: runtime error: slice bounds out of range [-1:]
internal/source/postgres.createTable ... postgres.go:92

The reader located the column list by searching the statement for the name's word, but the word splitter folds whitespace inside parentheses, so a name glued to a paren that opens a multi-line list is not in the text verbatim and the index was -1. The column list is now taken from the first parenthesis after TABLE, which the table name cannot contain. The same-line form (reports(id ...)) already worked and still does.

How it was found

Reading Mattermost's migrations (v10.11.0) while proving the MySQL reader against a real repository. Three of its Postgres files have this shape: 000016_create_reactions, 000043_thread_memberships, 000098_create_post_acknowledgements. Any repository with one of these would crash cdclint rather than lint it.

Verified

  • TestANameGluedToAMultiLineColumnListDoesNotPanic uses 000016's statement as written. It panics on main (checked by running it against the old file) and passes with the fix, including the second column's line number.
  • gofmt -l . clean, go vet, go test ./... pass; every corpus entry unchanged.
  • RefuseRadar: 0 error(s), 0 warning(s), 159 info, unchanged.

Why a separate PR

It is a crash in the shipped Postgres reader, found while working on the MySQL reader (which has its own copy of the fix). One concern per PR.

…Postgres reader

CREATE TABLE IF NOT EXISTS reactions( with the column list starting on
the next line made cdclint panic (slice bounds out of range [-1:]).
The reader found the column list by searching the statement for the
name's word, but the word splitter folds whitespace inside parentheses,
so a name glued to a paren that opens a multi-line list is not in the
text verbatim and the index came back -1. The column list is now taken
from the first parenthesis after TABLE, which the name cannot contain.

Found by reading Mattermost's migrations (v10.11.0), where three files
have this shape (000016_create_reactions, 000043_thread_memberships,
000098_create_post_acknowledgements). The same-line form, reports(id ...),
already worked and still does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant