Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WiEAD-0007kp-Dj for pgsql-bugs@arkaria.postgresql.org; Thu, 08 May 2014 02:34:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WiEAC-0003Yq-Nv for pgsql-bugs@arkaria.postgresql.org; Thu, 08 May 2014 02:34:24 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WiEAB-0003Yj-MT for pgsql-bugs@postgresql.org; Thu, 08 May 2014 02:34:23 +0000 Received: from mail-pa0-f49.google.com ([209.85.220.49]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WiEA8-00070m-Rq for pgsql-bugs@postgresql.org; Thu, 08 May 2014 02:34:22 +0000 Received: by mail-pa0-f49.google.com with SMTP id lj1so2016132pab.36 for ; Wed, 07 May 2014 19:34:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:content-type:content-transfer-encoding:mime-version; bh=RxP3UKjE5LR2gedCbgeNETjH5U9eeZaQrOplFdbhQjE=; b=JM+JKe+NKRkIuA4yef7iNqB16R8bdwut2FSqX9m2MqVyI6e1i1dhjkVRtrKesgnH97 b9Y0HL1FXYWcQ4/5PPQM386NakRGEFeKIMihc03RfEzdKxofQfOhYJV2wJHpzad9GsxM ptwYIxErY5aZbaXT8aY1dw+OmEsFgTcyIu7QlCZUqFBpfUdb8b8m1bSMrxghnOkHh0Ep g6bBAvliT3KXmaLVg+NRPMEefIGRzeQ8k5wA6pk3QP4WvD3+hfocjRq4IIWNjtSL1znQ PwYnZCHxQY1KIO2oAyHDCVtibU//8efBj2A131mjgS1pX4WSnan8rYD2VGnrVJrmrvpZ Ywrg== X-Gm-Message-State: ALoCoQn6HynZFZM1bsZKSS/N2lb+KibODfu7/GPE8fS9KhCb9q8f+WjAqr6ZGbkygJEdOG3Z6EFg X-Received: by 10.66.192.73 with SMTP id he9mr1904739pac.88.1399516459684; Wed, 07 May 2014 19:34:19 -0700 (PDT) Received: from ?IPv6:::1? ([2600:3c01::f03c:91ff:fe93:2ae4]) by mx.google.com with ESMTPSA id ki10sm5652150pbd.68.2014.05.07.19.34.18 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Wed, 07 May 2014 19:34:18 -0700 (PDT) Message-ID: <1399516457.27807.58.camel@sussancws0025> Subject: Re: can insert timestamp value that can't be read From: Jeff Davis To: Tom Lane Cc: pgsql-bugs@postgresql.org Date: Wed, 07 May 2014 19:34:17 -0700 In-Reply-To: <15053.1399438846@sss.pgh.pa.us> References: <1399415471.27807.49.camel@sussancws0025> <15053.1399438846@sss.pgh.pa.us> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On Wed, 2014-05-07 at 01:00 -0400, Tom Lane wrote: > Jeff Davis writes: > > It looks like timestamp[tz]_pl_interval() is not doing proper validation > > in all paths. > > > Patch attached. I looked for other areas that might be affected, but > > none jumped out. > > This seems to be adding a heck of a lot of cycles (viz, replacing a > simple int64 or float8 addition with timestamp2tm then tm2timestamp) > to fix a corner case that will probably not matter to anyone anytime > in the next 200 thousand years, give or take a few millenia. I'm okay > with the concept of detecting overflow here, but not at this price. > Can't we do a more direct overflow check, comparable to what ordinary > int64/float8 addition does? It's a bit more complex than that, because a similar example of the bug occurs without overflow when float timestamps are enabled. In timestamp2tm(), the date can end up larger than INT_MAX. In principle, I think the check in timestamp_pl_interval() can be quite cheap, because we essentially just need to check for overflow and do a bounds check. But it's hard to determine the precise valid bounds, and it seems a little fragile. I will see if I can extract the important parts of the validity check into a new function (or macro). It would need to match the other checks precisely though, otherwise this bug will persist. > Also, surely timestamp_mi_interval has got the identical issue, and > probably some other operators. timestamp_mi_interval() calls timestamp_pl_interval(). I'll take a look around for other similar problems though. Regards, Jeff Davis -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs