8 changes: 4 additions & 4 deletions internal/dcraw_fileio.cpp
Expand Up @@ -21,15 +21,15 @@ it under the terms of the one of three licenses as you choose:
for more information
*/

#line 3583 "dcraw/dcraw.c"
#line 3612 "dcraw/dcraw.c"
#include <math.h>
#define CLASS LibRaw::
#include "libraw/libraw_types.h"
#define LIBRAW_LIBRARY_BUILD
#include "libraw/libraw.h"
#include "internal/defines.h"
#include "internal/var_defines.h"
#line 3594 "dcraw/dcraw.c"
#line 3623 "dcraw/dcraw.c"

/*
Seach from the current directory up to the root looking for
Expand All @@ -55,7 +55,7 @@ void CLASS bad_pixels (const char *cfname)
#endif
if (cfname)
fp = fopen (cfname, "r");
#line 3645 "dcraw/dcraw.c"
#line 3674 "dcraw/dcraw.c"
if (!fp)
{
#ifdef LIBRAW_LIBRARY_BUILD
Expand Down Expand Up @@ -153,7 +153,7 @@ void CLASS subtract (const char *fname)
RUN_CALLBACK(LIBRAW_PROGRESS_DARK_FRAME,1,2);
#endif
}
#line 9567 "dcraw/dcraw.c"
#line 9603 "dcraw/dcraw.c"

#ifndef NO_LCMS
void CLASS apply_profile (const char *input, const char *output)
Expand Down
8 changes: 8 additions & 0 deletions src/libraw_datastream.cpp
Expand Up @@ -38,7 +38,12 @@ LibRaw_byte_buffer::~LibRaw_byte_buffer()

LibRaw_byte_buffer *LibRaw_abstract_datastream::make_byte_buffer(unsigned int sz)
{
if(sz> 2*1024*1024*1024) // 2GB is enough
throw LIBRAW_EXCEPTION_ALLOC;

LibRaw_byte_buffer *ret = new LibRaw_byte_buffer(sz);
if(!ret) // failed new should throw std::exception
throw LIBRAW_EXCEPTION_ALLOC;
read(ret->get_buffer(),sz,1);
return ret;
}
Expand Down Expand Up @@ -316,7 +321,10 @@ int LibRaw_buffer_datastream::scanf_one(const char *fmt, void* val)

LibRaw_byte_buffer *LibRaw_buffer_datastream::make_byte_buffer(unsigned int sz)
{

LibRaw_byte_buffer *ret = new LibRaw_byte_buffer(0);
if(!ret) // failed new should throw std::exception
throw LIBRAW_EXCEPTION_ALLOC;
if(streampos + sz > streamsize)
sz = streamsize - streampos;
ret->set_buffer(buf+streampos,sz);
Expand Down