unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] /srv/bzr/emacs/trunk r105581: Integer and memory overflow issues (Bug#9196).
Date: Fri, 26 Aug 2011 23:28:49 -0400	[thread overview]
Message-ID: <jwvei07czvc.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <E1Qx01t-0003DN-1m@vcs.savannah.gnu.org> (Paul Eggert's message of "Fri, 26 Aug 2011 09:36:17 -0700")

> +/* Size of header used by bidi_shelve_cache.  */
> +enum
> +  {
> +    bidi_shelve_header_size =
> +      (sizeof (bidi_cache_idx) + sizeof (bidi_cache_start_stack)
> +       + sizeof (bidi_cache_sp) + sizeof (bidi_cache_start)
> +       + sizeof (bidi_cache_last_idx))
> +  };

Why an enum?  Sounds really ugly!

> -	      if (outp - outbuf + MAX_MULTIBYTE_LENGTH * ccl.produced
> -		  > outbufsize)
> +	      /* FIXME: Surely this should be buf_magnification instead.
> +		 MAX_MULTIBYTE_LENGTH overestimates the storage needed.  */
> +	      int magnification = MAX_MULTIBYTE_LENGTH;
> +
> +	      ptrdiff_t offset = outp - outbuf;
> +	      ptrdiff_t shortfall;
> +	      if (INT_MULTIPLY_OVERFLOW (ccl.produced, magnification))
> +		memory_full (SIZE_MAX);
> +	      shortfall = ccl.produced * magnification - (outbufsize - offset);
> +	      if (0 < shortfall)

I don't want to sprinkle memory_full calls all over the code like your
patch does.

Especially since many of the overflow risks it fixes can only happen in
the case where we use 64bit Lisp_Objects on a 32bit system, which is not
currently the default and may end up never being the default (tho it may
also end up being the default, of course).

I.e. right now, those overflows don't worry me as much as the code
cleanliness which seems to suffer from your patch.


        Stefan



       reply	other threads:[~2011-08-27  3:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1Qx01t-0003DN-1m@vcs.savannah.gnu.org>
2011-08-27  3:28 ` Stefan Monnier [this message]
2011-08-27  7:17   ` [Emacs-diffs] /srv/bzr/emacs/trunk r105581: Integer and memory overflow issues (Bug#9196) Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvei07czvc.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).