Kaydet (Commit) f596e5d4 authored tarafından Caolán McNamara's avatar Caolán McNamara

ofz#799 stop decompressing if the file is truncated

Change-Id: I4040ebbf7b21905b950f4af36012bc83aebaa320
üst bed6a223
......@@ -33,15 +33,6 @@
#define JPEG_MIN_READ 512
#define BUFFER_SIZE 4096
/* Expanded data source object for stdio input */
struct SourceManagerStruct {
jpeg_source_mgr pub; /* public fields */
SvStream* stream; /* source stream */
JOCTET* buffer; /* start of buffer */
boolean start_of_file; /* have we gotten any data yet? */
};
/*
* Initialize source --- called by jpeg_read_header
* before any data is actually read.
......@@ -55,6 +46,7 @@ extern "C" void init_source (j_decompress_ptr cinfo)
* This is correct behavior for reading a series of images from one source.
*/
source->start_of_file = TRUE;
source->no_data_available = FALSE;
}
long StreamRead( SvStream* pStream, void* pBuffer, long nBufferSize )
......@@ -89,6 +81,7 @@ extern "C" boolean fill_input_buffer (j_decompress_ptr cinfo)
if (!nbytes)
{
source->no_data_available = TRUE;
if (source->start_of_file) /* Treat empty input file as fatal error */
{
ERREXIT(cinfo, JERR_INPUT_EMPTY);
......@@ -158,7 +151,7 @@ void jpeg_svstream_src (j_decompress_ptr cinfo, void* input)
(*cinfo->mem->alloc_small) (reinterpret_cast<j_common_ptr>(cinfo), JPOOL_PERMANENT, BUFFER_SIZE * sizeof(JOCTET)));
}
source = reinterpret_cast<SourceManagerStruct *>(cinfo->src);
source = reinterpret_cast<SourceManagerStruct*>(cinfo->src);
source->pub.init_source = init_source;
source->pub.fill_input_buffer = fill_input_buffer;
source->pub.skip_input_data = skip_input_data;
......
......@@ -34,6 +34,7 @@ namespace com { namespace sun { namespace star { namespace task {
class JPEGReader;
class JPEGWriter;
class Size;
class SvStream;
void jpeg_svstream_src (j_decompress_ptr cinfo, void* infile);
......@@ -49,6 +50,16 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines,
long Transform( void* pInputStream, void* pOutputStream, long nAngle );
/* Expanded data source object for stdio input */
struct SourceManagerStruct {
jpeg_source_mgr pub; /* public fields */
SvStream* stream; /* source stream */
JOCTET* buffer; /* start of buffer */
boolean start_of_file; /* have we gotten any data yet? */
boolean no_data_available;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -84,6 +84,7 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines,
jpeg_create_decompress( &cinfo );
jpeg_svstream_src( &cinfo, pInputStream );
SourceManagerStruct *source = reinterpret_cast<SourceManagerStruct*>(cinfo.src);
jpeg_read_header( &cinfo, TRUE );
cinfo.scale_num = 1;
......@@ -190,7 +191,7 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines,
}
}
for (*pLines = 0; *pLines < nHeight; (*pLines)++)
for (*pLines = 0; *pLines < nHeight && !source->no_data_available; (*pLines)++)
{
size_t yIndex = *pLines;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment