RE: [PATCH] Fix possible underflow in expression (maxoff - 1)

From: Ranier Vilela <ranier_gyn(at)hotmail(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: [PATCH] Fix possible underflow in expression (maxoff - 1)
Date: 2019-11-24 20:02:50
Message-ID: MN2PR18MB2927453D38E58F35E047563DE34B0@MN2PR18MB2927.namprd18.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>I think that you're being far too optimistic about your ability to
>detect and report valid issues using these static analysis tools. It's
>not possible to apply the information they provide without a high
l>evel understanding of the design of the code. There are already quite
>a few full time Postgres hackers that use tools like Coverity all the
>time.
I've been programming in C for a long time, and I'm getting better every day, I believe.
I'll arrive there.

>While it's certainly true that PageGetMaxOffsetNumber cannot in
>general be trusted to be > 0, we're talking about code that exists to
>deal with pages that are already full, and need to be split. It is
>impossible for "maxoff" to underflow, even if you deliberately corrupt
>a page image using a tool like pg_hexedit. Even if we failed to be
>sufficiently defensive about such a case (which is not the case), it
>wouldn't make any sense to fix it in this specific esoteric function,
>which is called when we've already decided to split the page (but only
>sometimes).
At this point you are right. I hope that in the future anyone who will use _bt_afternewitemoff will remember this hidden danger.

> Sanitization needs to happen at some central choke point.
Surely that would be the best solution. But this is not a function of a static analysis tool.

>I strongly suggest confining all of this to a single thread, and
>stating your reasoning upfront.
I don't know what that means.

Best regards.
Ranier Vilela

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2019-11-24 20:11:12 Re: [PATCH] Fix possible underflow in expression (maxoff - 1)
Previous Message Andreas Karlsson 2019-11-24 19:53:37 Minor white space typo in documentation