Skip to content

Commit

Permalink
when length/2 overflowed, uninitialized memory was put in the string …
Browse files Browse the repository at this point in the history
…buffer
  • Loading branch information
pietern committed Feb 10, 2010
1 parent 306a9f3 commit f15c95e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions ext/simple_mmap/mapped_file.c
Expand Up @@ -130,12 +130,11 @@ static VALUE sm_mapped_file_read_window_data(VALUE vself, VALUE voffset, VALUE v
return Qnil;
}

size_t curr;
curr = offset;
size_t curr = offset;
size_t i;
for(i = 0; i < length; ++i) {
//printf("i=%i offset=%i length=%i curr=%i map->len=%i\n", i, offset, length, curr, sm_map->len);
if ((curr + i) > sm_map->len)
if ((offset + i) > sm_map->len)
break;
buff[i] = sm_map->map[curr++];
}
Expand Down
4 changes: 4 additions & 0 deletions test/test_file_window.rb
Expand Up @@ -43,6 +43,10 @@ def test_get_bytes_past_length
assert_equal "z", @fw[25, 10]
end

def test_get_all_bytes
assert_equal ('a'..'z').to_a.join, @fw[0, 26]
end

def test_nil_on_negative_index
assert_equal nil, @fw[-1]
assert_equal nil, @fw[-1, 2]
Expand Down

0 comments on commit f15c95e

Please sign in to comment.