diff options
| author | Paul Eggert | 2011-07-14 23:44:47 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-14 23:44:47 -0700 |
| commit | f0eb61e99dce9005dc94c909046f6130b3d4a97c (patch) | |
| tree | 45628b2bdb6ff60123305d7f0d11b5d64c31c91a /src | |
| parent | 39e378da07fe365c6442dc95b937539eb31fe8ef (diff) | |
| download | emacs-f0eb61e99dce9005dc94c909046f6130b3d4a97c.tar.gz emacs-f0eb61e99dce9005dc94c909046f6130b3d4a97c.zip | |
* 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>.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 3 | ||||
| -rw-r--r-- | src/bidi.c | 13 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c19786fb72c..493b3277f52 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -15,6 +15,9 @@ | |||
| 15 | Don't set bidi_cache_size until after xrealloc returns, because it | 15 | Don't set bidi_cache_size until after xrealloc returns, because it |
| 16 | might not return. | 16 | might not return. |
| 17 | (bidi_dump_cached_states): Use ptrdiff_t, not int, to avoid overflow. | 17 | (bidi_dump_cached_states): Use ptrdiff_t, not int, to avoid overflow. |
| 18 | (bidi_cache_ensure_space): Also check that the bidi cache size | ||
| 19 | does not exceed that of the largest Lisp string or buffer. See Eli | ||
| 20 | Zaretskii in <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9079#29>. | ||
| 18 | 21 | ||
| 19 | * alloc.c (__malloc_size_t): Remove. | 22 | * alloc.c (__malloc_size_t): Remove. |
| 20 | All uses replaced by size_t. See Andreas Schwab's note | 23 | All uses replaced by size_t. See Andreas Schwab's note |
diff --git a/src/bidi.c b/src/bidi.c index 1999606639b..697ebb92856 100644 --- a/src/bidi.c +++ b/src/bidi.c | |||
| @@ -464,9 +464,16 @@ bidi_cache_ensure_space (ptrdiff_t idx) | |||
| 464 | if (idx >= bidi_cache_size) | 464 | if (idx >= bidi_cache_size) |
| 465 | { | 465 | { |
| 466 | ptrdiff_t new_size; | 466 | ptrdiff_t new_size; |
| 467 | ptrdiff_t max_size = | 467 | |
| 468 | min (PTRDIFF_MAX, SIZE_MAX) / elsz / BIDI_CACHE_CHUNK * BIDI_CACHE_CHUNK; | 468 | /* The bidi cache cannot be larger than the largest Lisp string |
| 469 | if (max_size <= idx) | 469 | or buffer. */ |
| 470 | ptrdiff_t string_or_buffer_bound = | ||
| 471 | max (BUF_BYTES_MAX, STRING_BYTES_BOUND); | ||
| 472 | |||
| 473 | /* Also, it cannot be larger than what C can represent. */ | ||
| 474 | ptrdiff_t c_bound = min (PTRDIFF_MAX, SIZE_MAX) / elsz; | ||
| 475 | |||
| 476 | if (min (string_or_buffer_bound, c_bound) <= idx) | ||
| 470 | memory_full (SIZE_MAX); | 477 | memory_full (SIZE_MAX); |
| 471 | new_size = idx - idx % BIDI_CACHE_CHUNK + BIDI_CACHE_CHUNK; | 478 | new_size = idx - idx % BIDI_CACHE_CHUNK + BIDI_CACHE_CHUNK; |
| 472 | bidi_cache = (struct bidi_it *) xrealloc (bidi_cache, new_size * elsz); | 479 | bidi_cache = (struct bidi_it *) xrealloc (bidi_cache, new_size * elsz); |