From de4c1f26d7a58f90fa72c734212878d7715bf6f9 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 12 Oct 2026 10:20:43 +0900 Subject: [PATCH] Limit the hexencode and bubblebabble results by RB_LEN_MAX The result is a String, whose length can exceed LONG_MAX on mswin. Co-Authored-By: Claude Opus 5.5 --- ext/digest/bubblebabble/bubblebabble.c | 6 +++++- ext/digest/digest.c | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/digest/bubblebabble/bubblebabble.c b/ext/digest/bubblebabble/bubblebabble.c index dac603c..26c6081 100644 --- a/ext/digest/bubblebabble/bubblebabble.c +++ b/ext/digest/bubblebabble/bubblebabble.c @@ -14,6 +14,10 @@ #include #include "../digest.h" +#ifndef HAVE_RB_LEN_T +# define RB_LEN_MAX LONG_MAX +#endif + static ID id_digest; static VALUE @@ -36,7 +40,7 @@ bubblebabble_str_new(VALUE str_digest) digest = RSTRING_PTR(str_digest); digest_len = RSTRING_LEN(str_digest); - if ((LONG_MAX - 2) / 3 < (digest_len | 1)) { + if ((RB_LEN_MAX - 2) / 3 < (digest_len | 1)) { rb_raise(rb_eRuntimeError, "digest string too long"); } diff --git a/ext/digest/digest.c b/ext/digest/digest.c index c3feab1..9ae244f 100644 --- a/ext/digest/digest.c +++ b/ext/digest/digest.c @@ -17,6 +17,7 @@ #include "digest.h" #ifndef HAVE_RB_LEN_T +# define RB_LEN_MAX LONG_MAX # define LEN2NUM LONG2NUM #endif @@ -116,7 +117,7 @@ hexencode_str_new(VALUE str_digest) digest = RSTRING_PTR(str_digest); digest_len = RSTRING_LEN(str_digest); - if (LONG_MAX / 2 < digest_len) { + if (RB_LEN_MAX / 2 < digest_len) { rb_raise(rb_eRuntimeError, "digest string too long"); }