Skip to content

Commit

Permalink
Fix libgit2#37, OID conversion with NULL bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg committed Dec 6, 2011
1 parent da3f66d commit 729eeef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ext/rugged/rugged.c
Expand Up @@ -43,7 +43,11 @@ static VALUE rb_git_raw_to_hex(VALUE self, VALUE raw)
char out[40];

Check_Type(raw, T_STRING);
git_oid_fromraw(&oid, StringValueCStr(raw));

if (RSTRING_LEN(raw) != GIT_OID_RAWSZ)
rb_raise(rb_eTypeError, "Invalid buffer size for an OID");

git_oid_fromraw(&oid, RSTRING_PTR(raw));
git_oid_fmt(out, &oid);

return rugged_str_new(out, 40, NULL);
Expand Down
7 changes: 7 additions & 0 deletions test/lib_test.rb
Expand Up @@ -30,4 +30,11 @@
hex2 = raw.unpack("H*")[0]
assert_equal hex1, hex2
end

test "converts raw into hex with null bytes" do
raw = Rugged::hex_to_raw("702f00394564b24052511cb69961164828bf5494")
hex1 = Rugged::raw_to_hex(raw)
hex2 = raw.unpack("H*")[0]
assert_equal hex1, hex2
end
end

0 comments on commit 729eeef

Please sign in to comment.