Merge pull request #5489 from RosettaCommons/vmullig/safer_binary_decoding
Revise utility::decode6bit() to avoid memory overruns
The function `utility::decode6bit()` accepts a pointer to a memory location and a string, decodes the string (converting every 4 characters into 3 bytes of arbitrary binary data), and populates a contiguous block of memory starting from the address stored in the pointer. There is no check that the memory that is overwritten is able to receive the data in question, and it's quite possible to run over the boundaries of a vector (especially if the vector length doesn't line up nicely with the 4 bytes of string per 3 bytes of data storage scheme). This PR alters the function signature so that it accepts a third input, the container size (in bytes), and refrains from writing beyond the container. While I don't think this fixes any existing bug (though it might -- it's hard to be 100% certain that there weren't cases in which container overruns were occurring), this does help to prevent mistakes in new code that calls this function. (I ran across this in the `vmullig/qpacker_benchmark` branch, pull request #4011, where I _was_ writing beyond the bounds of my vector and corrupting memory.)
DONE:
- [x] Teun's suggestions:
- [x] Update `/// @brief` for `encode6bit()`.
- [x] Add unit test.