You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been tinkering with replacing brotli with rust-brotli, and I've hit an interesting behavioral difference. The included C++ program works correctly when using the C brotli implementation, but segfaults with the Rust one:
#include<fstream>
#include<iostream>
#include<streambuf>
#include<string>
#include<string_view>
#include"brotli/encode.h"intmain(int argc, char** argv) {
if (argc < 2) {
std::cerr << "pass a file to compress" << std::endl;
return1;
}
std::string path = argv[1];
std::cout << "attempting to brotli-ize " << path << std::endl;
std::ifstream input_file(path);
std::string data((std::istreambuf_iterator<char>(input_file)),
std::istreambuf_iterator<char>());
std::string_view dv(data);
auto* state = BrotliEncoderCreateInstance(nullptr, nullptr, nullptr);
if (state == nullptr) {
std::cerr << "failed to make brotli encoder" << std::endl;
return1;
}
if (!BrotliEncoderSetParameter(state, BROTLI_PARAM_SIZE_HINT,
dv.size())) {
std::cerr << "failed to give brotli a size hint" << std::endl;
return1;
}
size_t in_left, out_left, written = 0;
BROTLI_BOOL result = BROTLI_TRUE;
while (dv.size() && result) {
in_left = dv.size();
out_left = 0;
constuint8_t* next_in = reinterpret_cast<constuint8_t*>(dv.data());
std::cout << "attempt to compress " << dv.size() << std::endl;
result =
BrotliEncoderCompressStream(state, BROTLI_OPERATION_PROCESS, &in_left,
&next_in, &out_left, nullptr, nullptr);
size_t buffer_size = 0;
/*const uint8_t* buf = */BrotliEncoderTakeOutput(state, &buffer_size);
if (buffer_size) {
written += buffer_size;
}
dv.remove_prefix(dv.size() - in_left);
}
while (result && !BrotliEncoderIsFinished(state)) {
in_left = 0;
out_left = 0;
constuint8_t* next_in = nullptr;
result = BrotliEncoderCompressStream(
state, BROTLI_OPERATION_FINISH, &in_left, &next_in,
&out_left, nullptr, nullptr);
size_t buffer_size = 0;
/*const uint8_t* buffer = */BrotliEncoderTakeOutput(state, &buffer_size);
if (buffer_size > 0) {
written += buffer_size;
}
}
BrotliEncoderDestroyInstance(state);
std::cout << "brotli'd down to " << written << " bytes" << std::endl;
return0;
}
I'm not familiar enough with the internals of rust-brotli to figure this out quickly, but I was hoping by filing a bug with a reduced test case might help someone figure this out. I think this might be related to #44, but I don't appear to need multiple chunks to trigger the segfault. As far as I can tell, the way this test program uses brotli is supported per the comments in encode.h, so I assume that the crasher in Rust is a bug of missing functionality and not merely a guard against an unexpected NULL.
The text was updated successfully, but these errors were encountered:
I've been tinkering with replacing brotli with rust-brotli, and I've hit an interesting behavioral difference. The included C++ program works correctly when using the C brotli implementation, but segfaults with the Rust one:
I'm not familiar enough with the internals of rust-brotli to figure this out quickly, but I was hoping by filing a bug with a reduced test case might help someone figure this out. I think this might be related to #44, but I don't appear to need multiple chunks to trigger the segfault. As far as I can tell, the way this test program uses brotli is supported per the comments in
encode.h
, so I assume that the crasher in Rust is a bug of missing functionality and not merely a guard against an unexpected NULL.The text was updated successfully, but these errors were encountered: