Skip to content

Commit

Permalink
Message size checking in libfec RS decoder
Browse files Browse the repository at this point in the history
This fixes a bug with the ESEO decoder. The RS decoder crashed giving std::bad_alloc
when it was passed a very short message.
  • Loading branch information
daniestevez committed Jan 6, 2019
1 parent c6d1329 commit 4f898c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/decode_rs_general_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ namespace gr {
int frame_len = pmt::length(msg);
size_t offset(0);

assert(frame_len <= MAX_FRAME_LEN);
if (frame_len <= d_nroots || frame_len > MAX_FRAME_LEN) {
if (d_verbose) {
std::printf("Reed-Solomon decoder: invalid frame length %d\n", frame_len);
return;
}
}

memset(data, 0, sizeof(data));
memcpy(data, pmt::uniform_vector_elements(msg, offset), frame_len);
Expand Down
9 changes: 7 additions & 2 deletions lib/decode_rs_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ namespace gr {
int frame_len = pmt::length(msg);
size_t offset(0);

assert(frame_len <= MAX_FRAME_LEN);

if (frame_len <= 32 || frame_len > MAX_FRAME_LEN) {
if (d_verbose) {
std::printf("Reed-Solomon decoder: invalid frame length %d\n", frame_len);
return;
}
}

memcpy(data, pmt::uniform_vector_elements(msg, offset), frame_len);

if (d_basis == BASIS_CONVENTIONAL) {
Expand Down

0 comments on commit 4f898c5

Please sign in to comment.