From: davecramer (@davecramer) <noreply+davecramer@github.com>
To: pgjdbc/pgjdbc <noreply+pgjdbc-pgjdbc@github.com>
Subject: Re: [pgjdbc/pgjdbc] PR #4332: fix: limit FINEST Bind, Parse and SimpleQuery log messages to maxLogMessageLength to avoid OOM
Date: Sat, 01 Aug 2026 09:34:49 +0000
Message-ID: <gh-pgjdbc-pgjdbc-4332-r4834402463@github.com> (raw)
In-Reply-To: <gh-pgjdbc-pgjdbc-4332@github.com>
References: <gh-pgjdbc-pgjdbc-4332@github.com>
## Review
Overall this is a clean, well-scoped, well-tested change. Conventions are followed (property definition, `getIntNoCheck` DataSource accessor matching the other int properties, copyright headers, FINEST guards), and the tests cover the small/capped/unlimited/huge-single-value cases plus the tiny-`maxLength` boundary of the suffix. I found no correctness bug that breaks well-formed logging. A few notes, the first worth addressing.
### 🟡 Medium — the "don't materialize huge values" guard misses value types `estimateLogSize` doesn't recognize
`estimateLogSize` only recognizes `byte[]`, `String`, `StreamWrapper`, and `ByteStreamWriter`; for anything else it returns `-1`. In `BindLog.format`, the placeholder short-circuit only fires when `estimated > remaining`:
```java
int estimated = params.estimateLogSize(i);
if (estimated > remaining) { // -1 > remaining is always false
... placeholder ...
continue;
}
String value = params.toString(i, standardConformingStrings); // full materialization
```
So for a value whose type isn't one of the four (e.g. a large array or `PGobject` bound via `setObject`), `estimated == -1`, the guard is skipped, and `toString(i, …)` **fully renders the value** before `appendBounded` trims it — which is exactly the materialization #995 is about. It's bounded per-message by `maxLogMessageLength` only *after* the full render, so it is no longer an unbounded OOM, but the protection is narrower than the PR implies.
Most large params in practice are `String` or `byte[]` (both covered), so this is a partial gap rather than a regression. Worth either (a) treating `estimated < 0` (unknown) as "render at most `remaining`, never more" — i.e. cap the intermediate render — or (b) documenting that the guard is best-effort for recognized types.
### Minor
- **Placeholder unit is mislabeled.** The oversized-value placeholder is `"...(" + estimated + " bytes)"`, but for a `String` parameter `estimateLogSize` returns `String.length()` (characters), and for bytea the rendered form is hex (~2× the raw bytes). "chars" or "~N bytes" would be more accurate than "bytes".
- **Dangling parameter fragment on budget exhaustion.** The loop appends `,$i=<` *before* recomputing `remaining` and breaking, so a capped line can end mid-parameter like `…,$37=<...(truncated)`. Cosmetic and arguably fine for a truncated debug dump, but computing `remaining` before appending the `,$i=<` prefix would produce cleaner output.
- **`estimateLogSize` `-1` semantics are overloaded.** The Javadoc says `-1` means "unknown / null", but callers can't distinguish the two and treat it as "small enough to render." Functionally fine; the comment just slightly oversells what `-1` conveys.
### Correctness spot-checks (all pass)
- Default `16384` preserves prior behaviour except for dumps that would exceed 16 KB — matches the description.
- `maxLogMessageLength` is clamped with `Math.max(0, …)` in the constructor, so a negative value cleanly means "unlimited".
- Both formatters sit inside `LOGGER.isLoggable(Level.FINEST)` guards, so there is zero cost when FINEST is off.
- Final `truncate(sbuf, maxLen)` guarantees the returned line never exceeds the cap even when intermediate appends (`">,type=…"`, `"})"`) overshoot.
### Recommendation
Good, focused fix with solid tests. Approve after either tightening the unknown-type materialization path (the Medium item) or documenting the guard as best-effort for recognized types; the rest are minor polish.