Skip to content
Permalink
Browse files Browse the repository at this point in the history
X3F property table list fix
  • Loading branch information
alextutubalin committed Apr 27, 2018
1 parent 895529f commit f0c505a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions internal/dcraw_common.cpp
Expand Up @@ -17602,6 +17602,7 @@ void CLASS identify()
tiff_ifd[i].dng_levels.analogbalance[c] = 1.0f;
}
#endif

memset(gpsdata, 0, sizeof gpsdata);
memset(cblack, 0, sizeof cblack);
memset(white, 0, sizeof white);
Expand Down
14 changes: 3 additions & 11 deletions internal/libraw_x3f.cpp
Expand Up @@ -121,8 +121,6 @@ typedef struct x3f_property_s {
/* Computed */
utf16_t *name; /* 0x0000 terminated UTF 16 */
utf16_t *value; /* 0x0000 terminated UTF 16 */
char *name_utf8; /* converted to UTF 8 */
char *value_utf8; /* converted to UTF 8 */
} x3f_property_t;

typedef struct x3f_property_table_s {
Expand Down Expand Up @@ -516,7 +514,6 @@ unsigned x3f_get4(LibRaw_abstract_datastream *f)
int _cur = _file->_func(_buffer,1,_left); \
if (_cur == 0) { \
throw LIBRAW_EXCEPTION_IO_CORRUPT; \
exit(1); \
} \
_left -= _cur; \
} \
Expand Down Expand Up @@ -912,11 +909,6 @@ static void free_camf_entry(camf_entry_t *entry)
if (PL)
{
int i;

for (i = 0; i < PL->property_table.size; i++) {
FREE(PL->property_table.element[i].name_utf8);
FREE(PL->property_table.element[i].value_utf8);
}
}
FREE(PL->property_table.element);
FREE(PL->data);
Expand Down Expand Up @@ -1624,14 +1616,14 @@ static void x3f_load_property_list(x3f_info_t *I, x3f_directory_entry_t *DE)

if (!PL->data_size)
PL->data_size = read_data_block(&PL->data, I, DE, 0);
uint32_t maxoffset = PL->data_size/sizeof(utf16_t)-2; // at least 2 chars, value + terminating 0x0000

for (i=0; i<PL->num_properties; i++) {
x3f_property_t *P = &PL->property_table.element[i];

if(P->name_offset > maxoffset || P->value_offset > maxoffset)
throw LIBRAW_EXCEPTION_IO_CORRUPT;
P->name = ((utf16_t *)PL->data + P->name_offset);
P->value = ((utf16_t *)PL->data + P->value_offset);
P->name_utf8 = 0;// utf16le_to_utf8(P->name);
P->value_utf8 = 0;//utf16le_to_utf8(P->value);
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/libraw_cxx.cpp
Expand Up @@ -6143,21 +6143,30 @@ void LibRaw::parse_x3f()
imgdata.sizes.raw_width = ID->columns;
imgdata.sizes.raw_height = ID->rows;
// Parse other params from property section

DE = x3f_get_prop(x3f);
if ((x3f_load_data(x3f, DE) == X3F_OK))
{
// Parse property list
DEH = &DE->header;
x3f_property_list_t *PL = &DEH->data_subsection.property_list;
utf16_t *datap = (utf16_t*) PL->data;
uint32_t maxitems = PL->data_size/sizeof(utf16_t);
if (PL->property_table.size != 0)
{
int i;
x3f_property_t *P = PL->property_table.element;
for (i = 0; i < PL->num_properties; i++)
{
char name[100], value[100];
utf2char(P[i].name, name,sizeof(name));
utf2char(P[i].value, value,sizeof(value));
int noffset = (P[i].name - datap);
int voffset = (P[i].value - datap);
if(noffset < 0 || noffset>maxitems || voffset<0 || voffset>maxitems)
throw LIBRAW_EXCEPTION_IO_CORRUPT;
int maxnsize = maxitems - (P[i].name - datap);
int maxvsize = maxitems - (P[i].value - datap);
utf2char(P[i].name, name,MIN(maxnsize,sizeof(name)));
utf2char(P[i].value, value,MIN(maxvsize,sizeof(value)));
if (!strcmp(name, "ISO"))
imgdata.other.iso_speed = atoi(value);
if (!strcmp(name, "CAMMANUF"))
Expand Down

0 comments on commit f0c505a

Please sign in to comment.