Skip to content

Commit 37a8983

Browse files
lgritzssh4net
authored andcommitted
fix: fix possible fmt exceptions where we might have passed null string (AcademySoftwareFoundation#5115)
I've heard occasional reports of uncaught exceptions in print statements. I haven't caught it in the act yet, but one set of reports involved the following output: OpenImageIO/detail/fmt/format-inl.h:40: assertion failed: string pointer is null So I'm proactively trying to find places that might be passing a null as a string. I'm just guessing here, but these are plausible candidates. --------- Signed-off-by: Larry Gritz <lg@larrygritz.com> Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com> Signed-off-by: Vlad <shaamaan@gmail.com>
1 parent 2060a57 commit 37a8983

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/libutil/strutil_test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,14 @@ test_string_view()
13281328
Strutil::print("addr cstr={:p}, s={:p}, ustring={:p}, sr={:p}, c_str(sr)={:p}\n",
13291329
(void*)cstr, (void*)s.c_str(), (void*)ustring(cstr).c_str(), (void*)sr.data(),
13301330
(void*)OIIO::c_str(sr));
1331+
1332+
// Test some edge cases for fmt formatting
1333+
string_view empty(""), uninit;
1334+
Strutil::print("Test print empty string_view: '{}'\n", empty);
1335+
Strutil::print("Test print default initialized string_view: '{}'\n", uninit);
1336+
OIIO_CHECK_EQUAL(empty, uninit);
1337+
OIIO_CHECK_EQUAL(Strutil::format("{}", empty),
1338+
Strutil::format("{}", uninit));
13311339
}
13321340

13331341

src/libutil/ustring_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ test_ustring()
167167
OIIO_CHECK_EQUAL(whichtype, ustring("foo"));
168168
OIIO_CHECK_ASSERT((std::is_same<decltype(whichtype), ustring>::value));
169169
OIIO_CHECK_ASSERT(!(std::is_same<decltype(whichtype), const char*>::value));
170+
171+
// Test some edge cases for fmt formatting
172+
Strutil::print("Test print empty ustring: '{}'\n", empty);
173+
Strutil::print("Test print default initialized ustring: '{}'\n", uninit);
174+
OIIO_CHECK_EQUAL(Strutil::format("{}", empty),
175+
Strutil::format("{}", uninit));
170176
}
171177

172178

src/raw.imageio/rawinput.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,16 +425,18 @@ RawInput::open_raw(bool unpack, bool process, const std::string& name,
425425
int ret = m_processor->open_file(name.c_str());
426426
#endif
427427
if (ret != LIBRAW_SUCCESS) {
428+
const char* err = libraw_strerror(ret);
428429
errorfmt("Could not open file \"{}\", {}", m_filename,
429-
libraw_strerror(ret));
430+
err ? err : "unknown error");
430431
return false;
431432
}
432433

433434
OIIO_ASSERT(!m_unpacked);
434435
if (unpack) {
435436
if ((ret = m_processor->unpack()) != LIBRAW_SUCCESS) {
437+
const char* err = libraw_strerror(ret);
436438
errorfmt("Could not unpack \"{}\", {}", m_filename,
437-
libraw_strerror(ret));
439+
err ? err : "unknown error");
438440
return false;
439441
}
440442
m_unpacked = true;
@@ -912,13 +914,16 @@ RawInput::open_raw(bool unpack, bool process, const std::string& name,
912914
// Get unadjusted max value (need to force a read first)
913915
ret = m_processor->raw2image_ex(/*subtract_black=*/true);
914916
if (ret != LIBRAW_SUCCESS) {
915-
errorfmt("HighlightMode adjustment detection read failed");
916-
errorfmt("{}", libraw_strerror(ret));
917+
const char* err = libraw_strerror(ret);
918+
errorfmt("HighlightMode adjustment detection read failed ({})",
919+
err ? err : "unknown error");
917920
return false;
918921
}
919-
if (m_processor->adjust_maximum() != LIBRAW_SUCCESS) {
920-
errorfmt("HighlightMode minimum adjustment failed");
921-
errorfmt("{}", libraw_strerror(ret));
922+
ret = m_processor->adjust_maximum();
923+
if (ret != LIBRAW_SUCCESS) {
924+
const char* err = libraw_strerror(ret);
925+
errorfmt("HighlightMode minimum adjustment failed ({})",
926+
err ? err : "unknown error");
922927
return false;
923928
}
924929
float unadjusted = m_processor->imgdata.color.maximum;
@@ -928,9 +933,11 @@ RawInput::open_raw(bool unpack, bool process, const std::string& name,
928933
= (old_max_thr == 0.0f) ? 1.0 : old_max_thr;
929934

930935
// Get new max value
931-
if (m_processor->adjust_maximum() != LIBRAW_SUCCESS) {
932-
errorfmt("HighlightMode maximum adjustment failed");
933-
errorfmt("{}", libraw_strerror(ret));
936+
ret = m_processor->adjust_maximum();
937+
if (ret != LIBRAW_SUCCESS) {
938+
const char* err = libraw_strerror(ret);
939+
errorfmt("HighlightMode maximum adjustment failed ({})",
940+
err ? err : "unknown error");
934941
return false;
935942
}
936943
float adjusted = m_processor->imgdata.color.maximum;
@@ -1566,7 +1573,9 @@ RawInput::do_process()
15661573
if (!m_image) {
15671574
int ret = m_processor->dcraw_process();
15681575
if (ret != LIBRAW_SUCCESS) {
1569-
errorfmt("Processing image failed, {}", libraw_strerror(ret));
1576+
const char* err = libraw_strerror(ret);
1577+
errorfmt("Processing image failed, {}",
1578+
err ? err : "unknown error");
15701579
return false;
15711580
}
15721581

0 commit comments

Comments
 (0)