Skip to content

Commit

Permalink
Fix bug to do invalid cast before check whether value is of int corre…
Browse files Browse the repository at this point in the history
…ctly or not
  • Loading branch information
tagomoris committed Sep 8, 2015
1 parent 7af6059 commit 76ba902
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ext/java/org/msgpack/jruby/Encoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@ private void appendExt(int type, ByteList payloadBytes) {
}

private void appendExtensionValue(ExtensionValue object) {
int type = (int) ((RubyFixnum)object.get_type()).getLongValue();
long type = ((RubyFixnum)object.get_type()).getLongValue();
if (type < -128 || type > 127) {
throw object.getRuntime().newRangeError(String.format("integer %d too big to convert to `signed char'", type));
}
ByteList payloadBytes = ((RubyString)object.payload()).getByteList();
appendExt(type, payloadBytes);
appendExt((int) type, payloadBytes);
}

private void appendOther(IRubyObject object, IRubyObject destination) {
Expand Down
6 changes: 3 additions & 3 deletions ext/java/org/msgpack/jruby/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public IRubyObject registerType(ThreadContext ctx, IRubyObject[] args) {
throw runtime.newArgumentError(String.format("wrong number of arguments (%d for 2..3)", 2 + args.length));
}

int typeId = (int) ((RubyFixnum) type).getLongValue();
long typeId = ((RubyFixnum) type).getLongValue();
if (typeId < -128 || typeId > 127) {
throw runtime.newRangeError(String.format("integer %d too big to convert to `signed char'", typeId));
}
Expand All @@ -118,8 +118,8 @@ public IRubyObject registerType(ThreadContext ctx, IRubyObject[] args) {
}
}

this.packerExtRegistry.put(extClass, typeId, packerProc, packerArg);
this.unpackerExtRegistry.put(extClass, typeId, unpackerProc, unpackerArg);
this.packerExtRegistry.put(extClass, (int) typeId, packerProc, packerArg);
this.unpackerExtRegistry.put(extClass, (int) typeId, unpackerProc, unpackerArg);

return runtime.getNil();
}
Expand Down

0 comments on commit 76ba902

Please sign in to comment.