5 changes: 4 additions & 1 deletion DesktopEditor/cximage/CxImage/ximage.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,11 @@ typedef struct tagCxTextInfo
//@}

/** \addtogroup Attributes */ //@{
int32_t GetSize();
uint32_t GetSize();
uint8_t* GetBits(uint32_t row = 0);
uint8_t GetColorType();
void* GetDIB() const;
void* GetDIBLimit() const;
uint32_t GetHeight() const;
uint32_t GetWidth() const;
uint32_t GetEffWidth() const;
Expand Down Expand Up @@ -796,6 +797,8 @@ typedef struct tagCxTextInfo
void bihtoh(BITMAPINFOHEADER* bih);

void* pDib; //contains the header, the palette, the pixels
void* pDibLimit;

BITMAPINFOHEADER head; //standard header
CXIMAGEINFO info; //extended information
uint8_t* pSelection; //selected region
Expand Down
10 changes: 8 additions & 2 deletions DesktopEditor/cximage/CxImage/ximaico.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ bool CxImageICO::Decode(CxFile *hFile)
// read the palette
RGBQUAD pal[256];
if (bih.biClrUsed)
hFile->Read(pal,bih.biClrUsed*sizeof(RGBQUAD), 1);
{
DWORD _count = bih.biClrUsed; if (_count > 256) _count = 256;
hFile->Read(pal,_count*sizeof(RGBQUAD), 1);
}
else
hFile->Read(pal,head.biClrUsed*sizeof(RGBQUAD), 1);
{
DWORD _count = head.biClrUsed; if (_count > 256) _count = 256;
hFile->Read(pal,_count*sizeof(RGBQUAD), 1);
}

SetPalette(pal,head.biClrUsed); //palette assign

Expand Down
4 changes: 4 additions & 0 deletions DesktopEditor/cximage/CxImage/ximainfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ void* CxImage::GetDIB() const
{
return pDib;
}
void* CxImage::GetDIBLimit() const
{
return pDibLimit;
}
////////////////////////////////////////////////////////////////////////////////
uint32_t CxImage::GetHeight() const
{
Expand Down
16 changes: 15 additions & 1 deletion DesktopEditor/cximage/CxImage/ximapcx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ bool CxImagePCX::Decode(CxFile *hFile)
info.xDPI = pcxHeader.Hres;
info.yDPI = pcxHeader.Vres;

if (Width <= 0 || Height <= 0)
cx_throw("Error: Not a PCX file");

if (info.nEscape == -1){
head.biWidth = Width;
head.biHeight= Height;
Expand All @@ -76,7 +79,11 @@ bool CxImagePCX::Decode(CxFile *hFile)

//Read the image and check if it's ok
nbytes = pcxHeader.BytesPerLine * pcxHeader.ColorPlanes * Height;
uint32_t pcximage_size = nbytes;
lpHead1 = pcximage = (uint8_t*)malloc(nbytes);
if (!pcximage)
cx_throw("Cancelled");

while (nbytes > 0){
if (hFile == NULL || hFile->Eof()) cx_throw("corrupted PCX");

Expand Down Expand Up @@ -119,6 +126,9 @@ bool CxImagePCX::Decode(CxFile *hFile)
for (uint32_t idx=0; idx<head.biClrUsed; idx++) SetPaletteColor((uint8_t)idx,ColorMap[idx][0],ColorMap[idx][1],ColorMap[idx][2]);

lpHead2 = pcxpixels = (uint8_t *)malloc(Width + pcxHeader.BytesPerLine * 8);
if (!pcxpixels)
cx_throw("Cancelled");

// Convert the image
for (y = 0; y < Height; y++){

Expand All @@ -138,7 +148,11 @@ bool CxImagePCX::Decode(CxFile *hFile)
} else if (pcxHeader.ColorPlanes == 4 && pcxHeader.BitsPerPixel == 8){
for (x = 0; x < Width; x++){
SetPixelColor(x,y2,RGB(pcxplanes[x],pcxplanes[pcxHeader.BytesPerLine + x],pcxplanes[2*pcxHeader.BytesPerLine + x]));
AlphaSet(x,y2,pcxplanes[3*pcxHeader.BytesPerLine + x]);

uint32_t alphaIndex = 3*pcxHeader.BytesPerLine + x;

if (alphaIndex < pcximage_size)
AlphaSet(x,y2,pcxplanes[alphaIndex]);
}
continue;
#endif //CXIMAGE_SUPPORT_ALPHA
Expand Down
19 changes: 15 additions & 4 deletions DesktopEditor/cximage/CxImage/ximatif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,16 @@ bool CxImageTIF::Decode(CxFile * hFile)
tilebuf = (uint8_t*)malloc(TIFFTileSize(m_tif));
}

bits = (uint8_t*)malloc(bitspersample==16? bitsize*2 : bitsize); // * VK
int32_t bitsize_correct = bitspersample==16? bitsize*2 : bitsize;
bits = (uint8_t*)malloc(bitsize_correct); // * VK
uint8_t * bits16 = NULL; // + VK
int32_t line16 = 0; // + VK

if (!tiled_image && bitspersample==16) { // + VK +
line16 = line;
line = CalculateLine(width, 8 * samplesperpixel);
bits16 = bits;
bitsize_correct = bitsize;
bits = (uint8_t*)malloc(bitsize);
}

Expand Down Expand Up @@ -454,9 +456,18 @@ bool CxImageTIF::Decode(CxFile * hFile)
double p,cx,cy,cz,cr,cg,cb;
while (ii</*line*/width){ // * VK
bitsoffset = ii*samplesperpixel+offset;
l=bits[bitsoffset];
a=bits[bitsoffset+1];
b=bits[bitsoffset+2];
if (bitsoffset + 2 < bitsize_correct)
{
l=bits[bitsoffset];
a=bits[bitsoffset+1];
b=bits[bitsoffset+2];
}
else
{
l=0;
a=0;
b=0;
}
if (a>127) a-=256;
if (b>127) b-=256;
// lab to xyz
Expand Down
3 changes: 2 additions & 1 deletion DesktopEditor/cximage/CxImage/xiofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ class DLL_EXP CxIOFile : public CxFile
return (bool)(iErr==0);
}
//////////////////////////////////////////////////////////
virtual size_t Read(void *buffer, size_t size, size_t count)
virtual size_t Read(void *buffer, size_t size, size_t count, void* limit_start = NULL, void* limit_end = NULL)
{
if (!m_fp) return 0;
clamp_buffer(buffer, size, limit_start, limit_end);
return fread(buffer, size, count, m_fp);
}
//////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions DesktopEditor/cximage/CxImage/xmemfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ uint8_t* CxMemFile::GetBuffer(bool bDetachBuffer)
return m_pBuffer;
}
//////////////////////////////////////////////////////////
size_t CxMemFile::Read(void *buffer, size_t size, size_t count)
size_t CxMemFile::Read(void *buffer, size_t size, size_t count, void* limit_start, void* limit_end)
{
if (buffer==NULL) return 0;

if (m_pBuffer==NULL) return 0;
if (m_Position >= (int32_t)m_Size){
m_bEOF = true;
return 0;
}
}

int32_t nCount = (int32_t)(count*size);
if (nCount == 0) return 0;
Expand Down
2 changes: 1 addition & 1 deletion DesktopEditor/cximage/CxImage/xmemfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DLL_EXP CxMemFile : public CxFile
uint8_t* GetBuffer(bool bDetachBuffer = true);

virtual bool Close();
virtual size_t Read(void *buffer, size_t size, size_t count);
virtual size_t Read(void *buffer, size_t size, size_t count, void* limit_start = NULL, void* limit_end = NULL);
virtual size_t Write(const void *buffer, size_t size, size_t count);
virtual bool Seek(int32_t offset, int32_t origin);
virtual int32_t Tell();
Expand Down
7 changes: 6 additions & 1 deletion DesktopEditor/cximage/jasper/jpc/jpc_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,12 @@ int jpc_ppxstab_insert(jpc_ppxstab_t *tab, jpc_ppxstabent_t *ent)
int inspt;
int i;

for (i = 0; i < tab->numents; ++i) {
// check on MAX_INT
int correct_num_ents = tab->numents;
if (correct_num_ents > 0x7FFFFFFE)
correct_num_ents = 0x7FFFFFFE;

for (i = 0; i < correct_num_ents; ++i) {
if (tab->ents[i]->ind > ent->ind) {
break;
}
Expand Down
25 changes: 18 additions & 7 deletions DesktopEditor/cximage/raw/libdcr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3518,20 +3518,21 @@ void DCR_CLASS dcr_cam_xyz_coeff (DCRAW* p, double cam_xyz[4][3])
{
double cam_rgb[4][3], inverse[4][3], num;
int i, j, k;

for (i=0; i < p->colors; i++) /* Multiply out XYZ colorspace */
int max_colors = p->colors;
if (max_colors > 4) max_colors = 4;
for (i=0; i < max_colors; i++) /* Multiply out XYZ colorspace */
for (j=0; j < 3; j++)
for (cam_rgb[i][j] = k=0; k < 3; k++)
cam_rgb[i][j] += cam_xyz[i][k] * xyz_rgb[k][j];

for (i=0; i < p->colors; i++) { /* Normalize cam_rgb so that */
for (i=0; i < max_colors; i++) { /* Normalize cam_rgb so that */
for (num=j=0; j < 3; j++) /* cam_rgb * (1,1,1) is (1,1,1,1) */
num += cam_rgb[i][j];
for (j=0; j < 3; j++)
cam_rgb[i][j] /= num;
p->pre_mul[i] = 1 / (float)num;
}
dcr_pseudoinverse (cam_rgb, inverse, p->colors);
dcr_pseudoinverse (cam_rgb, inverse, max_colors);
for (p->raw_color = i=0; i < 3; i++)
for (j=0; j < p->colors; j++)
p->rgb_cam[i][j] = (float)inverse[j][i];
Expand Down Expand Up @@ -5391,16 +5392,20 @@ void DCR_CLASS dcr_parse_tiff (DCRAW* p, int base)
p->tiff_ifd[raw].phint == 1) p->is_raw = 0;
if (p->tiff_bps == 8 && p->tiff_samples == 4) p->is_raw = 0;
for (i=0; i < (int)p->tiff_nifds; i++)
{
int sqr_1 = SQR(p->tiff_ifd[i].bps+1); if (sqr_1 == 0) sqr_1 = 1;
int sqr_2 = SQR(p->thumb_misc+1); if (sqr_2 == 0) sqr_2 = 1;
if (i != raw && p->tiff_ifd[i].samples == max_samp &&
p->tiff_ifd[i].width * p->tiff_ifd[i].height / SQR(p->tiff_ifd[i].bps+1) >
(int)(p->thumb_width * p->thumb_height / SQR(p->thumb_misc+1))) {
p->tiff_ifd[i].width * p->tiff_ifd[i].height / sqr_1 >
(int)(p->thumb_width * p->thumb_height / sqr_2)) {
p->thumb_width = p->tiff_ifd[i].width;
p->thumb_height = p->tiff_ifd[i].height;
p->thumb_offset = p->tiff_ifd[i].offset;
p->thumb_length = p->tiff_ifd[i].bytes;
p->thumb_misc = p->tiff_ifd[i].bps;
thm = i;
}
}
if (thm >= 0) {
p->thumb_misc |= p->tiff_ifd[thm].samples << 5;
switch (p->tiff_ifd[thm].comp) {
Expand Down Expand Up @@ -5845,10 +5850,16 @@ void DCR_CLASS dcr_parse_riff(DCRAW* p)
{ "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" };
struct tm t;

if (dcr_feof(p->obj_))
{
fprintf (stderr,_("Unexpected end of file\n"));
return;
}

p->order = 0x4949;
dcr_fread(p->obj_, tag, 4, 1);
size = dcr_get4(p);
end = dcr_ftell(p->obj_) + size;
end = dcr_ftell(p->obj_) + size;
if (!memcmp(tag,"RIFF",4) || !memcmp(tag,"LIST",4)) {
dcr_get4(p);
while (dcr_ftell(p->obj_)+7 < (long)end)
Expand Down
6 changes: 3 additions & 3 deletions DesktopEditor/cximage/tiff/tif_dirread.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ TIFFReadDirectory(TIFF* tif)
&& fix < tif->tif_nfields) {
if (fip->field_type == TIFF_ANY) /* wildcard */
break;
fip = tif->tif_fieldinfo[++fix];
++fix; fip = (fix >= tif->tif_nfields) ? 0 : tif->tif_fieldinfo[++fix];
if (fix >= tif->tif_nfields ||
fip->field_tag != dp->tdir_tag) {
TIFFWarningExt(tif->tif_clientdata, module,
Expand Down Expand Up @@ -333,7 +333,7 @@ TIFFReadDirectory(TIFF* tif)
&& fix < tif->tif_nfields) {
if (fip->field_type == TIFF_ANY) /* wildcard */
break;
fip = tif->tif_fieldinfo[++fix];
++fix; fip = (fix >= tif->tif_nfields) ? 0 : tif->tif_fieldinfo[++fix];
if (fix >= tif->tif_nfields ||
fip->field_tag != dp->tdir_tag) {
TIFFWarningExt(tif->tif_clientdata, module,
Expand Down Expand Up @@ -887,7 +887,7 @@ TIFFReadCustomDirectory(TIFF* tif, toff_t diroff,
&& fix < tif->tif_nfields) {
if (fip->field_type == TIFF_ANY) /* wildcard */
break;
fip = tif->tif_fieldinfo[++fix];
++fix; fip = (fix >= tif->tif_nfields) ? 0 : tif->tif_fieldinfo[++fix];
if (fix >= tif->tif_nfields ||
fip->field_tag != dp->tdir_tag) {
TIFFWarningExt(tif->tif_clientdata, module,
Expand Down
4 changes: 3 additions & 1 deletion DesktopEditor/cximage/tiff/tif_ojpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,9 @@ OJPEGReadBufferFill(OJPEGState* sp)
sp->in_buffer_file_pos=0;
else
{
sp->in_buffer_file_togo=sp->tif->tif_dir.td_stripbytecount[sp->in_buffer_next_strile];
sp->in_buffer_file_togo=0;
if (sp->tif->tif_dir.td_stripbytecount)
sp->in_buffer_file_togo=sp->tif->tif_dir.td_stripbytecount[sp->in_buffer_next_strile];
if (sp->in_buffer_file_togo==0)
sp->in_buffer_file_pos=0;
else if (sp->in_buffer_file_pos+sp->in_buffer_file_togo>sp->file_size)
Expand Down
5 changes: 4 additions & 1 deletion DesktopEditor/fontengine/fontconverter/FontFileType1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,13 +633,16 @@ namespace NSFontConverter
// (пробел, таб, перенос каретки или перенос строки).
unsigned char *sCur = (unsigned char*)(*ppEexecBuffer);
while( sCur < (unsigned char*)(*ppEexecBuffer) + nLen && ( ' ' == *sCur || '\t' == *sCur || '\r' == *sCur || '\n' == *sCur ) )
{
++sCur;
--nLen;
}

// Теперь нам надо определить в каком формате у нас данные: ASKII или бинарные данные.
// Если первые четыре байта являются шестнадцатиричными символами, значит, кодировка ASCII.
bool bASCII = false;

if ( isxdigit( sCur[0] ) && isxdigit( sCur[1] ) && isxdigit( sCur[2] ) && isxdigit( sCur[3] ) )
if ( nLen > 3 && isxdigit( sCur[0] ) && isxdigit( sCur[1] ) && isxdigit( sCur[2] ) && isxdigit( sCur[3] ) )
bASCII = true;

if ( bASCII )
Expand Down
2 changes: 2 additions & 0 deletions DesktopEditor/fontengine/fontconverter/FontFileType1.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ namespace NSFontConverter
}

sBuffer[nBufPos++] = unChar;
if (nBufPos >= c_nNumLimit)
break;
}

if ( 0 != sBuffer[0] && nCount > 0 )
Expand Down