Skip to content

Commit 8f47d52

Browse files
committed
Use long math to detect int overflow in expand
1 parent 5522f39 commit 8f47d52

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/java/org/jruby/ext/stringio/StringIO.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,12 @@ private void strioExtend(ThreadContext context, int pos, int len) {
984984
try {
985985
RubyString string = ptr.string;
986986
final int olen = string.size();
987-
if (pos + len > olen) {
988-
string.resize(pos + len);
987+
long newSize = (long) pos + len;
988+
if (newSize > Integer.MAX_VALUE) {
989+
throw context.runtime.newArgumentError("string size too big");
990+
}
991+
if (newSize > olen) {
992+
string.resize((int) newSize);
989993
if (pos > olen) {
990994
modifyString(string);
991995
ByteList ptrByteList = string.getByteList();

0 commit comments

Comments
 (0)