Skip to content

Commit

Permalink
Merge pull request #50 from prusa3d/et_fixes
Browse files Browse the repository at this point in the history
Fixed out of bound access in function MeatPack::unbinarize()
  • Loading branch information
enricoturri1966 authored Mar 18, 2024
2 parents 33a1eeb + 1d5e22e commit 638538c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/LibBGCode/binarize/meatpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,21 @@ void unbinarize(const std::vector<uint8_t>& src, std::string& dst)
is_gline_parameter(c_unbin[i])) {
*it_unbin_end = ' ';
++it_unbin_end;
if (it_unbin_end == unbin_buffer.end()) {
// the buffer is not big enough, resize it
unbin_buffer.resize(2 * unbin_buffer.size(), 0);
it_unbin_end = unbin_buffer.begin() + curr_unbin_buffer_length + 1;
}
}

if (c_unbin[i] != '\n' || std::distance(unbin_buffer.begin(), it_unbin_end) == 0 || *std::prev(it_unbin_end, 1) != '\n') {
*it_unbin_end = c_unbin[i];
++it_unbin_end;
if (it_unbin_end == unbin_buffer.end()) {
// the buffer is not big enough, resize it
unbin_buffer.resize(2 * unbin_buffer.size(), 0);
it_unbin_end = unbin_buffer.begin() + curr_unbin_buffer_length + 1;
}
}
}

Expand Down

0 comments on commit 638538c

Please sign in to comment.