Skip to content

Commit

Permalink
* pack.c (encodes): make buff fixed length to avoid SEGV by
Browse files Browse the repository at this point in the history
  ruby -e '["a"*10000000].pack("m1000000000")'


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
akr committed Sep 4, 2008
1 parent d44ee21 commit 40c771f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Fri Sep 5 00:05:27 2008 Tanaka Akira <[email protected]>

* pack.c (encodes): make buff fixed length to avoid SEGV by
ruby -e '["a"*10000000].pack("m1000000000")'

Thu Sep 4 23:47:05 2008 Yusuke Endoh <[email protected]>

* ext/bigdecimal/bigdecimal.c (BigDecimal_mode): set exception mode
Expand Down
21 changes: 14 additions & 7 deletions pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ static const char b64_table[] =
static void
encodes(VALUE str, const char *s, long len, int type)
{
char *buff = ALLOCA_N(char, len * 4 / 3 + 6);
char buff[4096];
long i = 0;
const char *trans = type == 'u' ? uu_table : b64_table;
int padding;
Expand All @@ -1022,13 +1022,20 @@ encodes(VALUE str, const char *s, long len, int type)
padding = '=';
}
while (len >= 3) {
buff[i++] = trans[077 & (*s >> 2)];
buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
buff[i++] = trans[077 & s[2]];
s += 3;
len -= 3;
while (len >= 3 && sizeof(buff)-i >= 4) {
buff[i++] = trans[077 & (*s >> 2)];
buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
buff[i++] = trans[077 & s[2]];
s += 3;
len -= 3;
}
if (sizeof(buff)-i < 4) {
rb_str_buf_cat(str, buff, i);
i = 0;
}
}

if (len == 2) {
buff[i++] = trans[077 & (*s >> 2)];
buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
Expand Down

0 comments on commit 40c771f

Please sign in to comment.