Skip to content

Commit

Permalink
fixed another security issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jkriege2 committed May 21, 2024
1 parent 3a8d9cc commit 4abede1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/tinymatwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,11 @@ const char *TinyMATWriter_getVersion()
else if (newsize < 1000 * 1024 * 1024) newsize = newsize * 3 / 2;
else newsize = newsize * 6 / 5;
}
file->filedata = (uint8_t*)realloc(file->filedata, newsize);
file->filedata_size = newsize;
auto newMem = (uint8_t*)realloc(file->filedata, newsize);
if (newMem) {
file->filedata=newMem;
file->filedata_size = newsize;
}
}
#endif
}
Expand Down Expand Up @@ -615,8 +618,10 @@ TINYMAT_inlineattrib static void TinyMAT_writeDatElement_string(TinyMATWriterFil
std::unique_ptr<int16_t[]> tmp;
if (slen>0 && data) {
tmp=std::unique_ptr<int16_t[]>(new int16_t[slen]);
for (uint32_t i=0; i<slen; i++) {
tmp[i]=data[i];
if (tmp) {
for (uint32_t i=0; i<slen; i++) {
tmp[i]=data[i];
}
}
}
uint32_t cla=TINYMAT_miUINT16;
Expand Down
14 changes: 8 additions & 6 deletions src/tinymatwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,14 @@ inline void TinyMATWriter_writeMatrixND_rowmajor(TinyMATWriterFile* mat, const c
freeDat=false;
} else {
dat=new T[nentries];//(T*)malloc(nentries*sizeof(T));
datOut=dat;
freeDat=true;
for (uint32_t m=0; m<nmatrices; m++) {
for(uint32_t r=0; r<rows; r++) {
for (uint32_t c=0; c<cols; c++) {
dat[m*cols*rows+c*rows+r]=data_real[m*cols*rows+r*cols+c];
if (dat) {
datOut=dat;
freeDat=true;
for (uint32_t m=0; m<nmatrices; m++) {
for(uint32_t r=0; r<rows; r++) {
for (uint32_t c=0; c<cols; c++) {
dat[m*cols*rows+c*rows+r]=data_real[m*cols*rows+r*cols+c];
}
}
}
}
Expand Down

0 comments on commit 4abede1

Please sign in to comment.