From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: JSON/YAML/TOML/etc. parsing performance Date: Wed, 04 Oct 2017 08:33:03 +0300 Message-ID: <83o9pnzddc.fsf@gnu.org> References: <87poaqhc63.fsf@lifelogs.com> <8360ceh5f1.fsf@gnu.org> <83h8vl5lf9.fsf@gnu.org> <83r2um3fqi.fsf@gnu.org> <43520b71-9e25-926c-d744-78098dad6441@cs.ucla.edu> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1507095210 30896 195.159.176.226 (4 Oct 2017 05:33:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 4 Oct 2017 05:33:30 +0000 (UTC) Cc: p.stephani2@gmail.com, emacs-devel@gnu.org To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 04 07:33:22 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzcJ5-0006o4-Dm for ged-emacs-devel@m.gmane.org; Wed, 04 Oct 2017 07:33:19 +0200 Original-Received: from localhost ([::1]:33201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzcJC-0002OB-KR for ged-emacs-devel@m.gmane.org; Wed, 04 Oct 2017 01:33:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzcJ6-0002O3-4X for emacs-devel@gnu.org; Wed, 04 Oct 2017 01:33:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzcJ3-0005s7-28 for emacs-devel@gnu.org; Wed, 04 Oct 2017 01:33:20 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:49929) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzcJ2-0005s3-Uu; Wed, 04 Oct 2017 01:33:16 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3512 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dzcJ2-0003be-AR; Wed, 04 Oct 2017 01:33:16 -0400 In-reply-to: <43520b71-9e25-926c-d744-78098dad6441@cs.ucla.edu> (message from Paul Eggert on Tue, 3 Oct 2017 13:52:54 -0700) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:219061 Archived-At: > Cc: emacs-devel@gnu.org > From: Paul Eggert > Date: Tue, 3 Oct 2017 13:52:54 -0700 > > > > +  if (buffer_and_size->size > PTRDIFF_MAX) > > > +    xsignal1 (Qoverflow_error, build_string ("buffer too large")); > > > +  insert (buffer_and_size->buffer, buffer_and_size->size); > > > > I don't think we need this test here, as 'insert' already has the > > equivalent test in one of its subroutines. > > > > It can't, because it takes the byte length as ptrdiff_t. We need to > > check before whether the size is actually in the valid range of ptrdiff_t. > > A PTRDIFF_MAX test is needed if the JSON library can return strings > longer than PTRDIFF_MAX. Please just use buffer_overflow () to signal > the error, though. I'd prefer to have such tests inside 'insert' and its subroutines, or to tweak the argument passed to 'insert' to have the existing checks catch the problem. Can we do that, please? It doesn't feel right to me to have this kind of checks in application C code.