Unverified Commit 828df46a authored by moto's avatar moto Committed by GitHub
Browse files

Fix segfault by calling ftell instead of tell_off (#1217)

[`sox_format_t.tell_off`](https://fossies.org/dox/sox-14.4.2/structsox__format__t.html#a2016a9fa839f3139e3c2f64381b0c445) should be representing current offset in file, but there are cases it does not. This was causing segmentation fault in some cases. This PR fixes it by replacing it with `ftell` call and add extra check so that if the same thing should happen, it will throw runtime error instead of segmentation fault.
parent 17aa81ea
...@@ -335,7 +335,17 @@ int fileobj_input_drain(sox_effect_t* effp, sox_sample_t* obuf, size_t* osamp) { ...@@ -335,7 +335,17 @@ int fileobj_input_drain(sox_effect_t* effp, sox_sample_t* obuf, size_t* osamp) {
// |**********|-----------------|++++++++++++| // |**********|-----------------|++++++++++++|
// ^ ftell // ^ ftell
const auto num_consumed = sf->tell_off; // NOTE:
// Do not use `sf->tell_off` here. Presumably, `tell_off` and `fseek` are
// supposed to be in sync, but there are cases (Vorbis) they are not
// in sync and `tell_off` has seemingly uninitialized value, which
// leads num_remain to be negative and cause segmentation fault
// in `memmove`.
const auto num_consumed = ftell((FILE*)sf->fp);
if (num_consumed > priv->buffer_size) {
throw std::runtime_error("Internal Error: buffer overrun.");
}
const auto num_remain = priv->buffer_size - num_consumed; const auto num_remain = priv->buffer_size - num_consumed;
// 1.1. Fetch the data to see if there is data to fill the buffer // 1.1. Fetch the data to see if there is data to fill the buffer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment