Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ext/zstdruby/skippable_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ static VALUE rb_write_skippable_frame(int argc, VALUE *argv, VALUE self)

StringValue(input_value);
StringValue(skip_value);
char* input_data = RSTRING_PTR(input_value);
size_t input_size = RSTRING_LEN(input_value);
char* skip_data = RSTRING_PTR(skip_value);
size_t skip_size = RSTRING_LEN(skip_value);

size_t dst_size = input_size + ZSTD_SKIPPABLEHEADERSIZE + skip_size;
VALUE output = rb_str_new(input_data, dst_size);
VALUE output = rb_str_new(NULL, dst_size);
char* output_data = RSTRING_PTR(output);
size_t output_size = ZSTD_writeSkippableFrame((void*)output_data, dst_size, (const void*)skip_data, skip_size, magic_variant);
if (ZSTD_isError(output_size)) {
Expand Down
8 changes: 8 additions & 0 deletions spec/zstd-skippable_frame_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@
end
end

context 'large input (heap-allocated) + skippable frame' do
it 'round-trips without breaking' do
payload = 'A' * 1024
skippable = 'sample data'
frame = Zstd.write_skippable_frame(payload, skippable)
expect(Zstd.read_skippable_frame(frame)).to eq skippable
end
end
end
end