Skip to content

Commit d366bb6

Browse files
Handle unknown type ids better
Some metadata has unknown type ids (data corruption or manufacturers stretching the standard) so something safer than 'at' is needed for map lookup.
1 parent b00d24d commit d366bb6

File tree

12 files changed

+123
-305
lines changed

12 files changed

+123
-305
lines changed

src/interface/shared/containers.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static PyObject* set_value_from_py(Exiv2::datum_type* datum,
5555
return SWIG_Py_Void();
5656
}
5757
// Try converting Python object to a value
58-
swig_type_info* ty_info = get_type_object.at(get_type_id(datum));
58+
swig_type_info* ty_info = get_type_object(get_type_id(datum));
5959
SwigPyClientData *cl_data = (SwigPyClientData*)ty_info->clientdata;
6060
// Call type object to invoke constructor
6161
PyObject* swig_obj = PyObject_CallFunctionObjArgs(

src/interface/value.i

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,45 +113,43 @@ OUTPUT_BUFFER_RW(Exiv2::byte* buf,)
113113

114114
// Downcast base class pointers to derived class
115115
// Convert exiv2 type id to the appropriate value class type info
116-
%fragment("_type_map_decl", "header") {
117-
#include <map>
118-
static std::map< Exiv2::TypeId, swig_type_info* > get_type_object;
119-
}
120-
%fragment("get_type_object", "init", fragment="_type_map_decl") {
121-
get_type_object = {
122-
{Exiv2::unsignedByte, $descriptor(Exiv2::DataValue*)},
116+
%fragment("_type_map_init", "init") {
117+
_type_object = {
123118
{Exiv2::asciiString, $descriptor(Exiv2::AsciiValue*)},
124119
{Exiv2::unsignedShort, $descriptor(Exiv2::ValueType<uint16_t>*)},
125120
{Exiv2::unsignedLong, $descriptor(Exiv2::ValueType<uint32_t>*)},
126121
{Exiv2::unsignedRational,
127122
$descriptor(Exiv2::ValueType<Exiv2::URational>*)},
128-
{Exiv2::signedByte, $descriptor(Exiv2::DataValue*)},
129-
{Exiv2::undefined, $descriptor(Exiv2::DataValue*)},
130123
{Exiv2::signedShort, $descriptor(Exiv2::ValueType<int16_t>*)},
131124
{Exiv2::signedLong, $descriptor(Exiv2::ValueType<int32_t>*)},
132125
{Exiv2::signedRational, $descriptor(Exiv2::ValueType<Exiv2::Rational>*)},
133126
{Exiv2::tiffFloat, $descriptor(Exiv2::ValueType<float>*)},
134127
{Exiv2::tiffDouble, $descriptor(Exiv2::ValueType<double>*)},
135128
{Exiv2::tiffIfd, $descriptor(Exiv2::ValueType<uint32_t>*)},
136-
{Exiv2::unsignedLongLong,
137-
$descriptor(Exiv2::DataValue*)},
138-
{Exiv2::signedLongLong, $descriptor(Exiv2::DataValue*)},
139-
{Exiv2::tiffIfd8, $descriptor(Exiv2::DataValue*)},
140129
{Exiv2::string, $descriptor(Exiv2::StringValue*)},
141130
{Exiv2::date, $descriptor(Exiv2::DateValue*)},
142131
{Exiv2::time, $descriptor(Exiv2::TimeValue*)},
143132
{Exiv2::comment, $descriptor(Exiv2::CommentValue*)},
144-
{Exiv2::directory, $descriptor(Exiv2::DataValue*)},
145133
{Exiv2::xmpText, $descriptor(Exiv2::XmpTextValue*)},
146134
{Exiv2::xmpAlt, $descriptor(Exiv2::XmpArrayValue*)},
147135
{Exiv2::xmpBag, $descriptor(Exiv2::XmpArrayValue*)},
148136
{Exiv2::xmpSeq, $descriptor(Exiv2::XmpArrayValue*)},
149-
{Exiv2::langAlt, $descriptor(Exiv2::LangAltValue*)},
150-
{Exiv2::invalidTypeId, $descriptor(Exiv2::DataValue*)}
137+
{Exiv2::langAlt, $descriptor(Exiv2::LangAltValue*)}
151138
};
152139
}
153-
140+
%fragment("get_type_object", "header", fragment="_type_map_init") {
141+
#include <map>
142+
static std::map<Exiv2::TypeId, swig_type_info*> _type_object;
154143
// Function to get swig type for an Exiv2 type id
144+
static swig_type_info* get_type_object(const Exiv2::TypeId type_id) {
145+
auto ptr = _type_object.find(type_id);
146+
if (ptr == _type_object.end())
147+
return $descriptor(Exiv2::DataValue*);
148+
return ptr->second;
149+
};
150+
}
151+
152+
// Function to get swig type for an Exiv2 value
155153
%fragment("get_swig_type", "header", fragment="get_type_object") {
156154
static swig_type_info* get_swig_type(Exiv2::Value* value) {
157155
Exiv2::TypeId type_id = value->typeId();
@@ -160,7 +158,7 @@ static swig_type_info* get_swig_type(Exiv2::Value* value) {
160158
if (dynamic_cast<Exiv2::CommentValue*>(value))
161159
return $descriptor(Exiv2::CommentValue*);
162160
}
163-
return get_type_object.at(type_id);
161+
return get_type_object(type_id);
164162
};
165163

166164
}

src/swig-0_27_7/exif_wrap.cxx

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5118,7 +5118,14 @@ SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c)
51185118

51195119

51205120

5121-
static std::map< Exiv2::TypeId, swig_type_info* > get_type_object;
5121+
static std::map<Exiv2::TypeId, swig_type_info*> _type_object;
5122+
// Function to get swig type for an Exiv2 type id
5123+
static swig_type_info* get_type_object(const Exiv2::TypeId type_id) {
5124+
auto ptr = _type_object.find(type_id);
5125+
if (ptr == _type_object.end())
5126+
return SWIGTYPE_p_Exiv2__DataValue;
5127+
return ptr->second;
5128+
};
51225129

51235130

51245131
static swig_type_info* get_swig_type(Exiv2::Value* value) {
@@ -5128,7 +5135,7 @@ static swig_type_info* get_swig_type(Exiv2::Value* value) {
51285135
if (dynamic_cast<Exiv2::CommentValue*>(value))
51295136
return SWIGTYPE_p_Exiv2__CommentValue;
51305137
}
5131-
return get_type_object.at(type_id);
5138+
return get_type_object(type_id);
51325139
};
51335140

51345141

@@ -5369,7 +5376,7 @@ static PyObject* set_value_from_py(Exiv2::Exifdatum* datum,
53695376
return SWIG_Py_Void();
53705377
}
53715378
// Try converting Python object to a value
5372-
swig_type_info* ty_info = get_type_object.at(get_type_id(datum));
5379+
swig_type_info* ty_info = get_type_object(get_type_id(datum));
53735380
SwigPyClientData *cl_data = (SwigPyClientData*)ty_info->clientdata;
53745381
// Call type object to invoke constructor
53755382
PyObject* swig_obj = PyObject_CallFunctionObjArgs(
@@ -13802,10 +13809,7 @@ SWIG_init(void) {
1380213809
return INIT_ERROR_RETURN;
1380313810

1380413811

13805-
get_type_object = {
13806-
{
13807-
Exiv2::unsignedByte, SWIGTYPE_p_Exiv2__DataValue
13808-
},
13812+
_type_object = {
1380913813
{
1381013814
Exiv2::asciiString, SWIGTYPE_p_Exiv2__AsciiValue
1381113815
},
@@ -13819,12 +13823,6 @@ SWIG_init(void) {
1381913823
Exiv2::unsignedRational,
1382013824
SWIGTYPE_p_Exiv2__ValueTypeT_std__pairT_uint32_t_uint32_t_t_t
1382113825
},
13822-
{
13823-
Exiv2::signedByte, SWIGTYPE_p_Exiv2__DataValue
13824-
},
13825-
{
13826-
Exiv2::undefined, SWIGTYPE_p_Exiv2__DataValue
13827-
},
1382813826
{
1382913827
Exiv2::signedShort, SWIGTYPE_p_Exiv2__ValueTypeT_int16_t_t
1383013828
},
@@ -13843,16 +13841,6 @@ SWIG_init(void) {
1384313841
{
1384413842
Exiv2::tiffIfd, SWIGTYPE_p_Exiv2__ValueTypeT_uint32_t_t
1384513843
},
13846-
{
13847-
Exiv2::unsignedLongLong,
13848-
SWIGTYPE_p_Exiv2__DataValue
13849-
},
13850-
{
13851-
Exiv2::signedLongLong, SWIGTYPE_p_Exiv2__DataValue
13852-
},
13853-
{
13854-
Exiv2::tiffIfd8, SWIGTYPE_p_Exiv2__DataValue
13855-
},
1385613844
{
1385713845
Exiv2::string, SWIGTYPE_p_Exiv2__StringValue
1385813846
},
@@ -13865,9 +13853,6 @@ SWIG_init(void) {
1386513853
{
1386613854
Exiv2::comment, SWIGTYPE_p_Exiv2__CommentValue
1386713855
},
13868-
{
13869-
Exiv2::directory, SWIGTYPE_p_Exiv2__DataValue
13870-
},
1387113856
{
1387213857
Exiv2::xmpText, SWIGTYPE_p_Exiv2__XmpTextValue
1387313858
},
@@ -13882,9 +13867,6 @@ SWIG_init(void) {
1388213867
},
1388313868
{
1388413869
Exiv2::langAlt, SWIGTYPE_p_Exiv2__LangAltValue
13885-
},
13886-
{
13887-
Exiv2::invalidTypeId, SWIGTYPE_p_Exiv2__DataValue
1388813870
}
1388913871
};
1389013872

src/swig-0_27_7/iptc_wrap.cxx

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5110,7 +5110,14 @@ SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c)
51105110

51115111

51125112

5113-
static std::map< Exiv2::TypeId, swig_type_info* > get_type_object;
5113+
static std::map<Exiv2::TypeId, swig_type_info*> _type_object;
5114+
// Function to get swig type for an Exiv2 type id
5115+
static swig_type_info* get_type_object(const Exiv2::TypeId type_id) {
5116+
auto ptr = _type_object.find(type_id);
5117+
if (ptr == _type_object.end())
5118+
return SWIGTYPE_p_Exiv2__DataValue;
5119+
return ptr->second;
5120+
};
51145121

51155122

51165123
static swig_type_info* get_swig_type(Exiv2::Value* value) {
@@ -5120,7 +5127,7 @@ static swig_type_info* get_swig_type(Exiv2::Value* value) {
51205127
if (dynamic_cast<Exiv2::CommentValue*>(value))
51215128
return SWIGTYPE_p_Exiv2__CommentValue;
51225129
}
5123-
return get_type_object.at(type_id);
5130+
return get_type_object(type_id);
51245131
};
51255132

51265133

@@ -5361,7 +5368,7 @@ static PyObject* set_value_from_py(Exiv2::Iptcdatum* datum,
53615368
return SWIG_Py_Void();
53625369
}
53635370
// Try converting Python object to a value
5364-
swig_type_info* ty_info = get_type_object.at(get_type_id(datum));
5371+
swig_type_info* ty_info = get_type_object(get_type_id(datum));
53655372
SwigPyClientData *cl_data = (SwigPyClientData*)ty_info->clientdata;
53665373
// Call type object to invoke constructor
53675374
PyObject* swig_obj = PyObject_CallFunctionObjArgs(
@@ -12004,10 +12011,7 @@ SWIG_init(void) {
1200412011
return INIT_ERROR_RETURN;
1200512012

1200612013

12007-
get_type_object = {
12008-
{
12009-
Exiv2::unsignedByte, SWIGTYPE_p_Exiv2__DataValue
12010-
},
12014+
_type_object = {
1201112015
{
1201212016
Exiv2::asciiString, SWIGTYPE_p_Exiv2__AsciiValue
1201312017
},
@@ -12021,12 +12025,6 @@ SWIG_init(void) {
1202112025
Exiv2::unsignedRational,
1202212026
SWIGTYPE_p_Exiv2__ValueTypeT_std__pairT_uint32_t_uint32_t_t_t
1202312027
},
12024-
{
12025-
Exiv2::signedByte, SWIGTYPE_p_Exiv2__DataValue
12026-
},
12027-
{
12028-
Exiv2::undefined, SWIGTYPE_p_Exiv2__DataValue
12029-
},
1203012028
{
1203112029
Exiv2::signedShort, SWIGTYPE_p_Exiv2__ValueTypeT_int16_t_t
1203212030
},
@@ -12045,16 +12043,6 @@ SWIG_init(void) {
1204512043
{
1204612044
Exiv2::tiffIfd, SWIGTYPE_p_Exiv2__ValueTypeT_uint32_t_t
1204712045
},
12048-
{
12049-
Exiv2::unsignedLongLong,
12050-
SWIGTYPE_p_Exiv2__DataValue
12051-
},
12052-
{
12053-
Exiv2::signedLongLong, SWIGTYPE_p_Exiv2__DataValue
12054-
},
12055-
{
12056-
Exiv2::tiffIfd8, SWIGTYPE_p_Exiv2__DataValue
12057-
},
1205812046
{
1205912047
Exiv2::string, SWIGTYPE_p_Exiv2__StringValue
1206012048
},
@@ -12067,9 +12055,6 @@ SWIG_init(void) {
1206712055
{
1206812056
Exiv2::comment, SWIGTYPE_p_Exiv2__CommentValue
1206912057
},
12070-
{
12071-
Exiv2::directory, SWIGTYPE_p_Exiv2__DataValue
12072-
},
1207312058
{
1207412059
Exiv2::xmpText, SWIGTYPE_p_Exiv2__XmpTextValue
1207512060
},
@@ -12084,9 +12069,6 @@ SWIG_init(void) {
1208412069
},
1208512070
{
1208612071
Exiv2::langAlt, SWIGTYPE_p_Exiv2__LangAltValue
12087-
},
12088-
{
12089-
Exiv2::invalidTypeId, SWIGTYPE_p_Exiv2__DataValue
1209012072
}
1209112073
};
1209212074

src/swig-0_27_7/metadatum_wrap.cxx

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5152,7 +5152,14 @@ SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c)
51525152

51535153

51545154

5155-
static std::map< Exiv2::TypeId, swig_type_info* > get_type_object;
5155+
static std::map<Exiv2::TypeId, swig_type_info*> _type_object;
5156+
// Function to get swig type for an Exiv2 type id
5157+
static swig_type_info* get_type_object(const Exiv2::TypeId type_id) {
5158+
auto ptr = _type_object.find(type_id);
5159+
if (ptr == _type_object.end())
5160+
return SWIGTYPE_p_Exiv2__DataValue;
5161+
return ptr->second;
5162+
};
51565163

51575164

51585165
static swig_type_info* get_swig_type(Exiv2::Value* value) {
@@ -5162,7 +5169,7 @@ static swig_type_info* get_swig_type(Exiv2::Value* value) {
51625169
if (dynamic_cast<Exiv2::CommentValue*>(value))
51635170
return SWIGTYPE_p_Exiv2__CommentValue;
51645171
}
5165-
return get_type_object.at(type_id);
5172+
return get_type_object(type_id);
51665173
};
51675174

51685175

@@ -7987,10 +7994,7 @@ SWIG_init(void) {
79877994
return INIT_ERROR_RETURN;
79887995

79897996

7990-
get_type_object = {
7991-
{
7992-
Exiv2::unsignedByte, SWIGTYPE_p_Exiv2__DataValue
7993-
},
7997+
_type_object = {
79947998
{
79957999
Exiv2::asciiString, SWIGTYPE_p_Exiv2__AsciiValue
79968000
},
@@ -8004,12 +8008,6 @@ SWIG_init(void) {
80048008
Exiv2::unsignedRational,
80058009
SWIGTYPE_p_Exiv2__ValueTypeT_std__pairT_uint32_t_uint32_t_t_t
80068010
},
8007-
{
8008-
Exiv2::signedByte, SWIGTYPE_p_Exiv2__DataValue
8009-
},
8010-
{
8011-
Exiv2::undefined, SWIGTYPE_p_Exiv2__DataValue
8012-
},
80138011
{
80148012
Exiv2::signedShort, SWIGTYPE_p_Exiv2__ValueTypeT_int16_t_t
80158013
},
@@ -8028,16 +8026,6 @@ SWIG_init(void) {
80288026
{
80298027
Exiv2::tiffIfd, SWIGTYPE_p_Exiv2__ValueTypeT_uint32_t_t
80308028
},
8031-
{
8032-
Exiv2::unsignedLongLong,
8033-
SWIGTYPE_p_Exiv2__DataValue
8034-
},
8035-
{
8036-
Exiv2::signedLongLong, SWIGTYPE_p_Exiv2__DataValue
8037-
},
8038-
{
8039-
Exiv2::tiffIfd8, SWIGTYPE_p_Exiv2__DataValue
8040-
},
80418029
{
80428030
Exiv2::string, SWIGTYPE_p_Exiv2__StringValue
80438031
},
@@ -8050,9 +8038,6 @@ SWIG_init(void) {
80508038
{
80518039
Exiv2::comment, SWIGTYPE_p_Exiv2__CommentValue
80528040
},
8053-
{
8054-
Exiv2::directory, SWIGTYPE_p_Exiv2__DataValue
8055-
},
80568041
{
80578042
Exiv2::xmpText, SWIGTYPE_p_Exiv2__XmpTextValue
80588043
},
@@ -8067,9 +8052,6 @@ SWIG_init(void) {
80678052
},
80688053
{
80698054
Exiv2::langAlt, SWIGTYPE_p_Exiv2__LangAltValue
8070-
},
8071-
{
8072-
Exiv2::invalidTypeId, SWIGTYPE_p_Exiv2__DataValue
80738055
}
80748056
};
80758057

0 commit comments

Comments
 (0)