Skip to content

Commit 30bb108

Browse files
Some XmpProperties methods can throw exceptions
Structured Xmp data with unknown inner namespaces can trigger an exception, even though the XmpKey value is valid.
1 parent 3b90776 commit 30bb108

File tree

4 files changed

+81
-12
lines changed

4 files changed

+81
-12
lines changed

src/interface/properties.i

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ EXCEPTION()
5858
%noexception Exiv2::XmpKey::tagLabel;
5959
%noexception Exiv2::XmpKey::tagName;
6060
%noexception Exiv2::XmpProperties::prefix;
61-
%noexception Exiv2::XmpProperties::propertyDesc;
62-
%noexception Exiv2::XmpProperties::propertyInfo;
63-
%noexception Exiv2::XmpProperties::propertyTitle;
64-
%noexception Exiv2::XmpProperties::propertyType;
6561

6662
EXTEND_KEY(Exiv2::XmpKey);
6763

src/swig-0_27_7/properties_wrap.cxx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5091,7 +5091,15 @@ SWIGINTERN PyObject *_wrap_XmpProperties_propertyTitle(PyObject *self, PyObject
50915091
SWIG_exception_fail(SWIG_NullReferenceError, "invalid null reference " "in method '" "XmpProperties_propertyTitle" "', argument " "1"" of type '" "Exiv2::XmpKey const &""'");
50925092
}
50935093
arg1 = reinterpret_cast< Exiv2::XmpKey * >(argp1);
5094-
result = (char *)Exiv2::XmpProperties::propertyTitle((Exiv2::XmpKey const &)*arg1);
5094+
{
5095+
try {
5096+
result = (char *)Exiv2::XmpProperties::propertyTitle((Exiv2::XmpKey const &)*arg1);
5097+
}
5098+
catch(std::exception const& e) {
5099+
_set_python_exception();
5100+
SWIG_fail;
5101+
}
5102+
}
50955103
resultobj = SWIG_FromCharPtr((const char *)result);
50965104
return resultobj;
50975105
fail:
@@ -5117,7 +5125,15 @@ SWIGINTERN PyObject *_wrap_XmpProperties_propertyDesc(PyObject *self, PyObject *
51175125
SWIG_exception_fail(SWIG_NullReferenceError, "invalid null reference " "in method '" "XmpProperties_propertyDesc" "', argument " "1"" of type '" "Exiv2::XmpKey const &""'");
51185126
}
51195127
arg1 = reinterpret_cast< Exiv2::XmpKey * >(argp1);
5120-
result = (char *)Exiv2::XmpProperties::propertyDesc((Exiv2::XmpKey const &)*arg1);
5128+
{
5129+
try {
5130+
result = (char *)Exiv2::XmpProperties::propertyDesc((Exiv2::XmpKey const &)*arg1);
5131+
}
5132+
catch(std::exception const& e) {
5133+
_set_python_exception();
5134+
SWIG_fail;
5135+
}
5136+
}
51215137
resultobj = SWIG_FromCharPtr((const char *)result);
51225138
return resultobj;
51235139
fail:
@@ -5143,7 +5159,15 @@ SWIGINTERN PyObject *_wrap_XmpProperties_propertyType(PyObject *self, PyObject *
51435159
SWIG_exception_fail(SWIG_NullReferenceError, "invalid null reference " "in method '" "XmpProperties_propertyType" "', argument " "1"" of type '" "Exiv2::XmpKey const &""'");
51445160
}
51455161
arg1 = reinterpret_cast< Exiv2::XmpKey * >(argp1);
5146-
result = (Exiv2::TypeId)Exiv2::XmpProperties::propertyType((Exiv2::XmpKey const &)*arg1);
5162+
{
5163+
try {
5164+
result = (Exiv2::TypeId)Exiv2::XmpProperties::propertyType((Exiv2::XmpKey const &)*arg1);
5165+
}
5166+
catch(std::exception const& e) {
5167+
_set_python_exception();
5168+
SWIG_fail;
5169+
}
5170+
}
51475171
{
51485172
resultobj = py_from_enum(Python_Exiv2_TypeId, static_cast<long>(result));
51495173
if (!resultobj)
@@ -5173,7 +5197,15 @@ SWIGINTERN PyObject *_wrap_XmpProperties_propertyInfo(PyObject *self, PyObject *
51735197
SWIG_exception_fail(SWIG_NullReferenceError, "invalid null reference " "in method '" "XmpProperties_propertyInfo" "', argument " "1"" of type '" "Exiv2::XmpKey const &""'");
51745198
}
51755199
arg1 = reinterpret_cast< Exiv2::XmpKey * >(argp1);
5176-
result = (Exiv2::XmpPropertyInfo *)Exiv2::XmpProperties::propertyInfo((Exiv2::XmpKey const &)*arg1);
5200+
{
5201+
try {
5202+
result = (Exiv2::XmpPropertyInfo *)Exiv2::XmpProperties::propertyInfo((Exiv2::XmpKey const &)*arg1);
5203+
}
5204+
catch(std::exception const& e) {
5205+
_set_python_exception();
5206+
SWIG_fail;
5207+
}
5208+
}
51775209
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Exiv2__XmpPropertyInfo, 0 | 0 );
51785210
return resultobj;
51795211
fail:

src/swig-0_28_7/properties_wrap.cxx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5091,7 +5091,15 @@ SWIGINTERN PyObject *_wrap_XmpProperties_propertyTitle(PyObject *self, PyObject
50915091
SWIG_exception_fail(SWIG_NullReferenceError, "invalid null reference " "in method '" "XmpProperties_propertyTitle" "', argument " "1"" of type '" "Exiv2::XmpKey const &""'");
50925092
}
50935093
arg1 = reinterpret_cast< Exiv2::XmpKey * >(argp1);
5094-
result = (char *)Exiv2::XmpProperties::propertyTitle((Exiv2::XmpKey const &)*arg1);
5094+
{
5095+
try {
5096+
result = (char *)Exiv2::XmpProperties::propertyTitle((Exiv2::XmpKey const &)*arg1);
5097+
}
5098+
catch(std::exception const& e) {
5099+
_set_python_exception();
5100+
SWIG_fail;
5101+
}
5102+
}
50955103
resultobj = SWIG_FromCharPtr((const char *)result);
50965104
return resultobj;
50975105
fail:
@@ -5117,7 +5125,15 @@ SWIGINTERN PyObject *_wrap_XmpProperties_propertyDesc(PyObject *self, PyObject *
51175125
SWIG_exception_fail(SWIG_NullReferenceError, "invalid null reference " "in method '" "XmpProperties_propertyDesc" "', argument " "1"" of type '" "Exiv2::XmpKey const &""'");
51185126
}
51195127
arg1 = reinterpret_cast< Exiv2::XmpKey * >(argp1);
5120-
result = (char *)Exiv2::XmpProperties::propertyDesc((Exiv2::XmpKey const &)*arg1);
5128+
{
5129+
try {
5130+
result = (char *)Exiv2::XmpProperties::propertyDesc((Exiv2::XmpKey const &)*arg1);
5131+
}
5132+
catch(std::exception const& e) {
5133+
_set_python_exception();
5134+
SWIG_fail;
5135+
}
5136+
}
51215137
resultobj = SWIG_FromCharPtr((const char *)result);
51225138
return resultobj;
51235139
fail:
@@ -5143,7 +5159,15 @@ SWIGINTERN PyObject *_wrap_XmpProperties_propertyType(PyObject *self, PyObject *
51435159
SWIG_exception_fail(SWIG_NullReferenceError, "invalid null reference " "in method '" "XmpProperties_propertyType" "', argument " "1"" of type '" "Exiv2::XmpKey const &""'");
51445160
}
51455161
arg1 = reinterpret_cast< Exiv2::XmpKey * >(argp1);
5146-
result = (Exiv2::TypeId)Exiv2::XmpProperties::propertyType((Exiv2::XmpKey const &)*arg1);
5162+
{
5163+
try {
5164+
result = (Exiv2::TypeId)Exiv2::XmpProperties::propertyType((Exiv2::XmpKey const &)*arg1);
5165+
}
5166+
catch(std::exception const& e) {
5167+
_set_python_exception();
5168+
SWIG_fail;
5169+
}
5170+
}
51475171
{
51485172
resultobj = py_from_enum(Python_Exiv2_TypeId, static_cast<long>(result));
51495173
if (!resultobj)
@@ -5173,7 +5197,15 @@ SWIGINTERN PyObject *_wrap_XmpProperties_propertyInfo(PyObject *self, PyObject *
51735197
SWIG_exception_fail(SWIG_NullReferenceError, "invalid null reference " "in method '" "XmpProperties_propertyInfo" "', argument " "1"" of type '" "Exiv2::XmpKey const &""'");
51745198
}
51755199
arg1 = reinterpret_cast< Exiv2::XmpKey * >(argp1);
5176-
result = (Exiv2::XmpPropertyInfo *)Exiv2::XmpProperties::propertyInfo((Exiv2::XmpKey const &)*arg1);
5200+
{
5201+
try {
5202+
result = (Exiv2::XmpPropertyInfo *)Exiv2::XmpProperties::propertyInfo((Exiv2::XmpKey const &)*arg1);
5203+
}
5204+
catch(std::exception const& e) {
5205+
_set_python_exception();
5206+
SWIG_fail;
5207+
}
5208+
}
51775209
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Exiv2__XmpPropertyInfo, 0 | 0 );
51785210
return resultobj;
51795211
fail:

tests/test_properties.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ def test_XmpProperties(self):
7474
exiv2.TypeId, exiv2.TypeId.langAlt)
7575
self.check_result(properties.propertyType(key2),
7676
exiv2.TypeId, exiv2.TypeId.xmpText)
77+
key = exiv2.XmpKey('Xmp.iptcExt.ImageRegion[1]/invalid-ns:Value')
78+
with self.assertRaises(exiv2.Exiv2Error):
79+
properties.propertyDesc(key)
80+
with self.assertRaises(exiv2.Exiv2Error):
81+
properties.propertyInfo(key)
82+
with self.assertRaises(exiv2.Exiv2Error):
83+
properties.propertyTitle(key)
84+
with self.assertRaises(exiv2.Exiv2Error):
85+
properties.propertyType(key)
7786
namespaces = properties.registeredNamespaces()
7887
self.assertIsInstance(namespaces, dict)
7988
self.assertGreater(len(namespaces), 0)

0 commit comments

Comments
 (0)