all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 9079@debbugs.gnu.org
Subject: bug#9079: integer overflow etc. issues (e.g., image crashes Emacs)
Date: Fri, 15 Jul 2011 00:22:44 -0700	[thread overview]
Message-ID: <4E1FEAC4.9000000@cs.ucla.edu> (raw)
In-Reply-To: <83aacghz98.fsf@gnu.org>

On 07/14/11 22:46, Eli Zaretskii wrote:

> why is it a good idea to use ptrdiff_t instead of EMACS_INT?

Normally, ptrdiff_t and EMACS_INT are the same, but if --with-wide-int
is specified on a 32-bit host, ptrdiff_t is half the size of EMACS_INT
and is therefore more efficient.  That is, if a value is guaranteed
to fit within both ptrdiff_t and EMACS_INT ranges, then it's typically
better to store it in a ptrdiff_t variable.

> the bidi cache can never be longer than the longest Lisp
> string or buffer.  So having a cache longer than that is already a
> bug, and we should announce memory full when a Lisp integer overflows.

Thanks, I didn't know about that constraint.  More precisely, we
should announce memory full when either (1) the size of the longest
Lisp string or buffer is exceeded, or (2) the limits of the bidi
cache's underlying C representation are exceeded.  The code was
already doing (2) but it was not doing (1).

A further patch to do that is below.


* bidi.c (bidi_cache_ensure_space): Also check that the bidi cache size
does not exceed that of the largest Lisp string or buffer.  See Eli
Zaretskii in <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9079#29>.
=== modified file 'src/bidi.c'
--- src/bidi.c	2011-07-14 21:57:00 +0000
+++ src/bidi.c	2011-07-15 06:43:47 +0000
@@ -464,9 +464,16 @@
   if (idx >= bidi_cache_size)
     {
       ptrdiff_t new_size;
-      ptrdiff_t max_size =
-	min (PTRDIFF_MAX, SIZE_MAX) / elsz / BIDI_CACHE_CHUNK * BIDI_CACHE_CHUNK;
-      if (max_size <= idx)
+
+      /* The bidi cache cannot be larger than the largest Lisp string
+	 or buffer.  */
+      ptrdiff_t string_or_buffer_bound =
+	max (BUF_BYTES_MAX, STRING_BYTES_BOUND);
+
+      /* Also, it cannot be larger than what C can represent.  */
+      ptrdiff_t c_bound = min (PTRDIFF_MAX, SIZE_MAX) / elsz;
+
+      if (min (string_or_buffer_bound, c_bound) <= idx)
 	memory_full (SIZE_MAX);
       new_size = idx - idx % BIDI_CACHE_CHUNK + BIDI_CACHE_CHUNK;
       bidi_cache = (struct bidi_it *) xrealloc (bidi_cache, new_size * elsz);







  reply	other threads:[~2011-07-15  7:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-14  7:55 bug#9079: integer overflow etc. issues (e.g., image crashes Emacs) Paul Eggert
2011-07-14  8:22 ` Andreas Schwab
2011-07-14 16:15   ` Paul Eggert
2011-07-14  8:47 ` Eli Zaretskii
2011-07-14 16:23   ` Paul Eggert
2011-07-14 17:48     ` Eli Zaretskii
2011-07-14 22:02   ` Paul Eggert
2011-07-15  5:46     ` Eli Zaretskii
2011-07-15  7:22       ` Paul Eggert [this message]
2011-07-14 12:54 ` Leo
     [not found] ` <handler.9079.B.13106301884386.ack@debbugs.gnu.org>
2011-07-28  0:49   ` bug#9079: Acknowledgement (integer overflow etc. issues (e.g., image crashes Emacs)) 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

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

  git send-email \
    --in-reply-to=4E1FEAC4.9000000@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=9079@debbugs.gnu.org \
    --cc=eliz@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.