Assertion error on buffer_id for yr_rules_load_stream #1358
Description
I just recently upgraded to 4.0.2 from 3.11.0, and without any other changes I am getting a new assertion error that I wasn't previously getting when loading compiled Yara rules from memory with yr_rules_load_stream with "large" Yara rulesets.
Assertion failed: buffer_id < arena->num_buffers, file ......\libyara\arena.c, line 390
Example code:
YR_STREAM yr_stream_disk;
yr_stream_disk.user_data = &stream_disk;
yr_stream_disk.read = (YR_STREAM_READ_FUNC)read_yara_stream;
result = yr_rules_load_stream(&yr_stream_disk, &rules_disk);
stream_disk
is a custom struct that gets passed to my read function read_yara_stream
below:
size_t read_yara_stream(void *buffer, size_t size, size_t count, void *user_data) {
char *buf = (char *)buffer;
STREAM *stream = (STREAM *)user_data;
size_t n;
for (n = 0; n < count; n++) {
if (size) {
memcpy(buf, stream->_ptr, size);
stream->_ptr += size;
stream->_cnt -= size;
buf += size;
}
}
return n;
}
Based on my testing I can only reproduce this error when I am loading in rulesets that are larger than roughly ~180KB (non-compiled) and/or ~570KB compiled. This could still be user error on my part, but it seems odd that I can run these compiled rulesets (and some much larger) with the Yara binary, but then those same rulesets loading dynamically through yr_rules_load_stream error out with this assertion error once the rulesets get too large.