pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
report expected contrecord size
7+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2020-09-04 f43e295f68  Report expected contrecord length on mismatch
* report expected contrecord size
@ 2020-09-03 21:21  Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Alvaro Herrera @ 2020-09-03 21:21 UTC (permalink / raw)
  To: Pg Hackers <pgsql-hackers@lists.postgresql.org>

A pretty minor issue: when reporting that WAL appears invalid because
contrecord length doesn't match, we may as well print to the server log
the value that we're expecting.  Patch attached.

-- 
Álvaro Herrera                         http://www.flickr.com/photos/alvherre/

Attachments:

report-contrecord.patch (text/x-diff, 671B) download diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index 67996018da..b69cf80b59 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -464,8 +464,9 @@ XLogReadRecord(XLogReaderState *state, char **errormsg) total_len != (pageHeader->xlp_rem_len + gotlen)) { report_invalid_record(state, - "invalid contrecord length %u at %X/%X", + "invalid contrecord length %u (expected %lld) at %X/%X", pageHeader->xlp_rem_len, + (long long) total_len - gotlen, (uint32) (RecPtr >> 32), (uint32) RecPtr); goto err; }
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: report expected contrecord size
@ 2020-09-03 21:31  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2020-09-03 21:31 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> A pretty minor issue: when reporting that WAL appears invalid because
> contrecord length doesn't match, we may as well print to the server log
> the value that we're expecting.  Patch attached.

ITYW

+                                      (long long) (total_len - gotlen),

just to be sure about what's getting casted to what.  Otherwise +1.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: report expected contrecord size
@ 2020-09-03 22:00  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Alvaro Herrera @ 2020-09-03 22:00 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

On 2020-Sep-03, Tom Lane wrote:

> Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> > A pretty minor issue: when reporting that WAL appears invalid because
> > contrecord length doesn't match, we may as well print to the server log
> > the value that we're expecting.  Patch attached.
> 
> ITYW
> 
> +                                      (long long) (total_len - gotlen),
> 
> just to be sure about what's getting casted to what.

Well, the intention there is to cast the first operand (which is uint32)
so that it turns into signed 64-bits; the subtraction then occurs in 64
bit arithmetic normally.  If I let the subtraction occur in 32-bit width
unsigned, the result might overflow 32 bits.  I'm thinking in
1 - UINT32_MAX or some such.

Maybe to make that more explicit, it should be

+                                      ((long long) total_len) - gotlen,

(If I understand the precedence correctly, it's the same thing I wrote).

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: report expected contrecord size
@ 2020-09-03 22:17  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2020-09-03 22:17 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> Well, the intention there is to cast the first operand (which is uint32)
> so that it turns into signed 64-bits; the subtraction then occurs in 64
> bit arithmetic normally.  If I let the subtraction occur in 32-bit width
> unsigned, the result might overflow 32 bits.

Uh ... is it really possible for gotlen to be more than total_len?
(I've not looked at the surrounding code here, but that seems weird.)

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: report expected contrecord size
@ 2020-09-03 22:33  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Alvaro Herrera @ 2020-09-03 22:33 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

On 2020-Sep-03, Tom Lane wrote:

> Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> > Well, the intention there is to cast the first operand (which is uint32)
> > so that it turns into signed 64-bits; the subtraction then occurs in 64
> > bit arithmetic normally.  If I let the subtraction occur in 32-bit width
> > unsigned, the result might overflow 32 bits.
> 
> Uh ... is it really possible for gotlen to be more than total_len?
> (I've not looked at the surrounding code here, but that seems weird.)

Well, as I understand, total_len comes from one page, and gotlen comes
from the continuation record(s) in the next page(s) of WAL.  So if
things are messed up, it could happen.  (This *is* the code that
validates the record, so it can't make too many assumptions.)

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: report expected contrecord size
@ 2020-09-03 22:42  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2020-09-03 22:42 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> On 2020-Sep-03, Tom Lane wrote:
>> Uh ... is it really possible for gotlen to be more than total_len?
>> (I've not looked at the surrounding code here, but that seems weird.)

> Well, as I understand, total_len comes from one page, and gotlen comes
> from the continuation record(s) in the next page(s) of WAL.  So if
> things are messed up, it could happen.  (This *is* the code that
> validates the record, so it can't make too many assumptions.)

Got it.  No further objections.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: report expected contrecord size
@ 2020-09-04 19:00  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Alvaro Herrera @ 2020-09-04 19:00 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

On 2020-Sep-03, Tom Lane wrote:

> Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> > On 2020-Sep-03, Tom Lane wrote:
> >> Uh ... is it really possible for gotlen to be more than total_len?
> >> (I've not looked at the surrounding code here, but that seems weird.)
> 
> > Well, as I understand, total_len comes from one page, and gotlen comes
> > from the continuation record(s) in the next page(s) of WAL.  So if
> > things are messed up, it could happen.  (This *is* the code that
> > validates the record, so it can't make too many assumptions.)
> 
> Got it.  No further objections.

Many thanks for looking!  Pushed now.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2020-09-04 19:00 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03 21:21 report expected contrecord size Alvaro Herrera <alvherre@2ndquadrant.com>
2020-09-03 21:31 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-09-03 22:00   ` Alvaro Herrera <alvherre@2ndquadrant.com>
2020-09-03 22:17     ` Tom Lane <tgl@sss.pgh.pa.us>
2020-09-03 22:33       ` Alvaro Herrera <alvherre@2ndquadrant.com>
2020-09-03 22:42         ` Tom Lane <tgl@sss.pgh.pa.us>
2020-09-04 19:00           ` Alvaro Herrera <alvherre@2ndquadrant.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox