Skip to content

Commit

Permalink
Merge pull request #218 from Flamefire/catch_osx-sonoma-iconv-issue
Browse files Browse the repository at this point in the history
Catch OSX sonoma iconv issue
  • Loading branch information
Flamefire authored Feb 12, 2024
2 parents 7da8ce3 + 5f2a828 commit 299381b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/boost/locale/encoding/iconv_converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ namespace boost { namespace locale { namespace conv { namespace impl {
} else
break;
} else if(err == E2BIG) {
BOOST_VERIFY_MSG(in_left != old_in_left || output_count != 0, "No progress, IConv is faulty!");
continue;
if(in_left != old_in_left || out_ptr != out_start) // Check to avoid infinite loop
continue;
throw std::runtime_error("No progress, IConv is faulty!"); // LCOV_EXCL_LINE
} else // Invalid error code, shouldn't ever happen or iconv has a bug
throw conversion_error(); // LCOV_EXCL_LINE
}
Expand Down
30 changes: 26 additions & 4 deletions test/test_encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ const bool test_iso_8859_8 =
hasWinCodepage(28598);
#endif

#if defined(BOOST_LOCALE_WITH_ICONV)
// Reproduce issue #206 to detect faulty IConv
static bool isFaultyIconv()
{
namespace blc = boost::locale::conv;
auto from_utf = blc::detail::make_utf_decoder<char>("ISO-2022-CN", blc::skip, blc::detail::conv_backend::IConv);
try {
from_utf->convert("");
} catch(const std::runtime_error& e) { // LCOV_EXCL_LINE
return std::string(e.what()).find("IConv is faulty") != std::string::npos; // LCOV_EXCL_LINE
}
return false;
}
#else
constexpr bool isFaultyIconv()
{
return false;
}
#endif

constexpr boost::locale::conv::detail::conv_backend all_conv_backends[] = {
#ifdef BOOST_LOCALE_WITH_ICONV
boost::locale::conv::detail::conv_backend::IConv,
Expand Down Expand Up @@ -318,10 +338,12 @@ void test_utf_for()
} catch(const invalid_charset_error&) { // LCOV_EXCL_LINE
std::cout << "--- not supported\n"; // LCOV_EXCL_LINE
}
// Testing a codepage which may crash with IConv on macOS, see issue #196
test_to_from_utf<Char>("\xa1\xad\xa1\xad", utf<Char>("……"), "gbk", false);
// This might cause a bogus E2BIG on macOS, see issue #206
test_to_from_utf<Char>("\x1b\x24\x29\x41\x0e\x4a\x35\xf", utf<Char>(""), "ISO-2022-CN", false);
if(!isFaultyIconv()) {
// Testing a codepage which may crash with IConv on macOS, see issue #196
test_to_from_utf<Char>("\xa1\xad\xa1\xad", utf<Char>("……"), "gbk", false);
// This might cause a bogus E2BIG on macOS, see issue #206
test_to_from_utf<Char>("\x1b\x24\x29\x41\x0e\x4a\x35\xf", utf<Char>(""), "ISO-2022-CN", false);
}

std::cout << "- Testing correct invalid bytes skipping\n";
{
Expand Down

0 comments on commit 299381b

Please sign in to comment.