Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

fix(tzl): reject invalid frame buffer sizes in legacy .tlv loaders

chantologyca0ae1b6db35
diff --git a/toonz/sources/image/tzl/tiio_tzl.cpp b/toonz/sources/image/tzl/tiio_tzl.cpp
index 4332cf884..3ccfd9ffa 100644
--- a/toonz/sources/image/tzl/tiio_tzl.cpp
+++ b/toonz/sources/image/tzl/tiio_tzl.cpp
@@ -1638,14 +1638,16 @@ m_lrp->m_frameIndex = m_frameIndex;*/
reverse((char *)&ydpi, sizeof(double));
#endif
+ delete[] imgBuff;
+ imgBuff = 0;
+
imgBuffSize = m_lx * m_ly * sizeof(TPixelCM32);
assert(actualBuffSize <= imgBuffSize);
+ if (actualBuffSize <= 0 || actualBuffSize > imgBuffSize)
+ throw TException("Loading tlv: buffer size error");
- delete[] imgBuff;
imgBuff = new UCHAR[imgBuffSize];
- // int ret =
fread(imgBuff, actualBuffSize, 1, chan);
- // assert(ret==1);
}
Header *header = (Header *)imgBuff;
@@ -1762,11 +1764,11 @@ m_lrp->m_frameIndex = m_frameIndex;*/
imgBuffSize = m_lx * m_ly * sizeof(TPixelCM32);
assert(actualBuffSize <= imgBuffSize);
+ if (actualBuffSize <= 0 || actualBuffSize > imgBuffSize)
+ throw TException("Loading tlv: buffer size error");
imgBuff = new UCHAR[imgBuffSize];
- // int ret =
fread(imgBuff, actualBuffSize, 1, chan);
- // assert(ret==1);
Header *header = (Header *)imgBuff;
@@ -1796,8 +1798,6 @@ m_lrp->m_frameIndex = m_frameIndex;*/
}
ras->unlock();
}
-
-// codec.compress(ras, 1, &imgBuff, actualBuffSize);
#endif
TRect savebox(TPoint(sbx0, sby0), TDimension(sblx, sbly));
@@ -1815,18 +1815,9 @@ m_lrp->m_frameIndex = m_frameIndex;*/
delete[] imgBuff;
- // codec.decompress(m_compressedBuffer, m_compressedBufferSize, ras);
-
- // assert(0);
- // TToonzImageP ti; // = new
- // TToonzImage(m_lx,m_ly,savebox,imgBuff,actualBuffSize);
TToonzImageP ti(ras, savebox);
- // if(dpiflag)
ti->setDpi(xdpi, ydpi);
- // m_lrp->m_level->setFrame(TFrameId(m_frameIndex+1), ti);
ti->setPalette(m_lrp->m_level->getPalette());
- // delete [] imgBuff;
- // imgBuff = 0;
return ti;
// ToonzImageUtils::updateRas32(ti);
@@ -1882,7 +1873,9 @@ TImageP TImageReaderTzl::load13() {
fread(&actualBuffSize, sizeof(TINT32), 1, chan);
imgBuffSize = (iconLx * iconLy * sizeof(TPixelCM32));
- imgBuff = new UCHAR[imgBuffSize];
+ if (actualBuffSize <= 0 || actualBuffSize > imgBuffSize)
+ throw TException("Loading tlv: icon buffer size error.");
+ imgBuff = new UCHAR[imgBuffSize];
fread(imgBuff, actualBuffSize, 1, chan);
#if !TNZ_LITTLE_ENDIAN
@@ -1956,17 +1949,14 @@ TImageP TImageReaderTzl::load13() {
return ti;
}
+ if (actualBuffSize <= 0 ||
+ actualBuffSize > (int)(m_lx * m_ly * sizeof(TPixelCM32)))
+ throw TException("Loading tlv: buffer size error");
+
TRasterCM32P raux = TRasterCM32P(m_lx, m_ly);
raux->lock();
- imgBuff = (UCHAR *)raux->getRawData(); // new UCHAR[imgBuffSize];
- // imgBuff = new UCHAR[imgBuffSize];
- // imgBuffSize = m_lx*m_ly*sizeof(TPixelCM32);
- // assert(actualBuffSize <= imgBuffSize);
-
- // imgBuff = new UCHAR[imgBuffSize];
- // int ret =
+ imgBuff = (UCHAR *)raux->getRawData();
fread(imgBuff, actualBuffSize, 1, chan);
- // assert(ret==1);
Header *header = (Header *)imgBuff;
@@ -2467,9 +2457,14 @@ const TImageInfo *TImageReaderTzl::getImageInfo10() const {
reverse((char *)&ydpi, sizeof(double));
#endif
+ delete[] imgBuff;
+ imgBuff = 0;
+
imgBuffSize = m_lx * m_ly * sizeof(TPixelCM32);
assert(actualBuffSize <= imgBuffSize);
- delete[] imgBuff;
+ if (actualBuffSize <= 0 || actualBuffSize > imgBuffSize)
+ throw TException("Loading tlv: buffer size error");
+
imgBuff = new UCHAR[imgBuffSize];
fread(imgBuff, actualBuffSize, 1, chan);
}