Fix a potential out-of-bounds read

This commit is contained in:
Nobuyoshi Nakada committed 2026-07-09 20:46:27 +09:00
1 parent edf0ea0355
commit 835ad5c09e
1 file changed
+7 -6
Notes: git 2026-07-09 12:18:28 +00:00
+7 -6
View File
@@ -208,12 +208,12 @@ skip_to_eol(const char *p, const char *pend)
(ISSPACE(type) || (type == '#' && (p = skip_to_eol(p, pend), 1)))
#ifndef NATINT_PACK
# define pack_modifiers(p, t, n, e) pack_modifiers(p, t, e)
# define pack_modifiers(p, pe, t, n, e) pack_modifiers(p, pe, t, e)
#endif
static char *
pack_modifiers(const char *p, char type, int *natint, int *explicit_endian)
static const char *
pack_modifiers(const char *p, const char *pend, char type, int *natint, int *explicit_endian)
{
while (1) {
while (p < pend) {
switch (*p) {
case '_':
case '!':
@@ -242,6 +242,7 @@ pack_modifiers(const char *p, char type, int *natint, int *explicit_endian)
return (char *)p;
}
}
return p;
}
static VALUE
@@ -289,7 +290,7 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer)
#endif
if (skip_blank(p, type)) continue;
p = pack_modifiers(p, type, &natint, &explicit_endian);
p = pack_modifiers(p, pend, type, &natint, &explicit_endian);
if (*p == '*') { /* set data length */
len = strchr("@Xxu", type) ? 0
@@ -1046,7 +1047,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, VALUE ofs, enum unpack_mode mode)
int star = 0;
if (skip_blank(p, type)) continue;
p = pack_modifiers(p, type, &natint, &explicit_endian);
p = pack_modifiers(p, pend, type, &natint, &explicit_endian);
if (p >= pend)
len = 1;