Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RLE buffer overflow #4

Merged
merged 1 commit into from
Aug 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion make_library
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# Edit these values when building a new version of the library
major=2
minor=0
rel=4
rel=5

os=`uname`
if [ _$os = "_OS/390" ]
Expand Down
12 changes: 10 additions & 2 deletions rlencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,22 @@ char message[MAX_MESSAGE_SIZE];
#define debug 0
/*
* runlenEncode returns RL_OK if success, RL_ERR if input the number of
* points encoded is not equal to input full length. "thinlen" contains
* the size of the encoded field on return. Missing data values represented
* points encoded is not equal to input full length. On entry,"thinlen" must
* be set to the size of the thinvec buffer. On exit, "thinlen" contains
* the size of the encoded field. Missing data values represented
* by "bmdi" are mapped into a single missing data value followed
* by an integer value indicating the length of the run of missing data
* values. fatvec and thinvec are the expanded (input) and compressed (output)
* fields respectively.
*
*/
int runlen_encode (float *fatvec, int fatlen, float *thinvec, int *thinlen, float bmdi, function* parent)
{
int i = 0; /* loop over expanded field */
int nmdi = 0; /* length of current run of mdi */
int tmdi = 0; /* Count of total number of mdi */
int other = 0; /* Count of total number of non mdi */
int maxthinlen = *thinlen;
float *vp = thinvec; /* pointer used to set encoded field */
function subroutine;
int log_messages=(get_verbosity()>=VERBOSITY_MESSAGE);
Expand All @@ -60,6 +63,11 @@ int runlen_encode (float *fatvec, int fatlen, float *thinvec, int *thinlen, floa
if (*fatvec == bmdi) {
nmdi++, tmdi++;
} else {
// Check whether we have enough room in thinvec for what we're
// about to store.
if (*thinlen + 1 + 2 * (nmdi > 0) > maxthinlen) {
return RL_ERR;
}
if (nmdi > 0) {
if ((tmdi + other) <= fatlen) {
if (log_messages) {
Expand Down