Skip to content

Commit

Permalink
merge revision(s) 19346c2: [Backport #19754]
Browse files Browse the repository at this point in the history
	[Bug #19754] Make `IO::Buffer#get_string` check `offset` range
	 (ruby#8016)

	---
	 io_buffer.c                 | 3 +++
	 test/ruby/test_io_buffer.rb | 8 ++++++++
	 2 files changed, 11 insertions(+)
  • Loading branch information
nagachika committed Oct 28, 2023
1 parent 2d6067d commit 8bbf909
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion io_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,11 @@ rb_io_buffer_free(VALUE self)
static inline void
io_buffer_validate_range(struct rb_io_buffer *data, size_t offset, size_t length)
{
if (offset > data->size) {
rb_raise(rb_eArgError, "Specified offset exceeds buffer size!");
}
if (offset + length > data->size) {
rb_raise(rb_eArgError, "Specified offset+length exceeds data size!");
rb_raise(rb_eArgError, "Specified offset+length exceeds buffer size!");
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/ruby/test_io_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ def test_get_string

chunk = buffer.get_string(0, message.bytesize, Encoding::BINARY)
assert_equal Encoding::BINARY, chunk.encoding

assert_raise_with_message(ArgumentError, /exceeds buffer size/) do
buffer.get_string(0, 129)
end

assert_raise_with_message(ArgumentError, /exceeds buffer size/) do
buffer.get_string(129)
end
end

# We check that values are correctly round tripped.
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 2
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 126
#define RUBY_PATCHLEVEL 127

#include "ruby/version.h"
#include "ruby/internal/abi.h"
Expand Down

0 comments on commit 8bbf909

Please sign in to comment.