diff --git a/OpenCC-ver.1.0.5.tar.gz b/OpenCC-ver.1.0.5.tar.gz new file mode 100644 index 0000000..0d54bde Binary files /dev/null and b/OpenCC-ver.1.0.5.tar.gz differ diff --git a/opencc-check-bounds.patch b/opencc-check-bounds.patch new file mode 100644 index 0000000..9ed7c20 --- /dev/null +++ b/opencc-check-bounds.patch @@ -0,0 +1,35 @@ +Index: OpenCC-ver.1.0.5/src/BinaryDict.cpp +=================================================================== +--- OpenCC-ver.1.0.5.orig/src/BinaryDict.cpp ++++ OpenCC-ver.1.0.5/src/BinaryDict.cpp +@@ -63,6 +63,12 @@ void BinaryDict::SerializeToFile(FILE* f + } + + BinaryDictPtr BinaryDict::NewFromFile(FILE* fp) { ++ size_t offsetBound, savedOffset; ++ savedOffset = ftell(fp); ++ fseek(fp, 0L, SEEK_END); ++ offsetBound = ftell(fp) - savedOffset; ++ fseek(fp, savedOffset, SEEK_SET); ++ + BinaryDictPtr dict(new BinaryDict(LexiconPtr(new Lexicon))); + + // Number of items +@@ -109,7 +115,7 @@ BinaryDictPtr BinaryDict::NewFromFile(FI + // Key offset + size_t keyOffset; + unitsRead = fread(&keyOffset, sizeof(size_t), 1, fp); +- if (unitsRead != 1) { ++ if (unitsRead != 1 || keyOffset >= offsetBound) { + throw InvalidFormat("Invalid OpenCC binary dictionary (keyOffset)"); + } + const char* key = dict->keyBuffer.c_str() + keyOffset; +@@ -118,7 +124,7 @@ BinaryDictPtr BinaryDict::NewFromFile(FI + for (size_t j = 0; j < numValues; j++) { + size_t valueOffset; + unitsRead = fread(&valueOffset, sizeof(size_t), 1, fp); +- if (unitsRead != 1) { ++ if (unitsRead != 1 || valueOffset >= offsetBound) { + throw InvalidFormat("Invalid OpenCC binary dictionary (valueOffset)"); + } + const char* value = dict->valueBuffer.c_str() + valueOffset; diff --git a/opencc-fixes-cmake.patch b/opencc-fixes-cmake.patch new file mode 100644 index 0000000..c70ce95 --- /dev/null +++ b/opencc-fixes-cmake.patch @@ -0,0 +1,26 @@ +Index: OpenCC-ver.1.0.5/CMakeLists.txt +=================================================================== +--- OpenCC-ver.1.0.5.orig/CMakeLists.txt ++++ OpenCC-ver.1.0.5/CMakeLists.txt +@@ -68,7 +68,7 @@ set (DIR_PREFIX ${CMAKE_INSTALL_PREFIX}) + set (DIR_INCLUDE ${DIR_PREFIX}/include/) + set (DIR_SHARE ${DIR_PREFIX}/share/) + set (DIR_ETC ${DIR_PREFIX}/etc/) +-set (DIR_LIBRARY ${DIR_PREFIX}/lib${LIB_SUFFIX}/) ++set (DIR_LIBRARY ${LIB_INSTALL_DIR}) + + if (DEFINED SHARE_INSTALL_PREFIX) + set (DIR_SHARE ${SHARE_INSTALL_PREFIX}) +Index: OpenCC-ver.1.0.5/data/CMakeLists.txt +=================================================================== +--- OpenCC-ver.1.0.5.orig/data/CMakeLists.txt ++++ OpenCC-ver.1.0.5/data/CMakeLists.txt +@@ -1,6 +1,6 @@ + set(OPENCC_DICT_BIN opencc_dict) +-set(DICT_MERGE_BIN python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/merge.py) +-set(DICT_REVERSE_BIN python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/reverse.py) ++set(DICT_MERGE_BIN python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/merge.py) ++set(DICT_REVERSE_BIN python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/reverse.py) + set(DICT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dictionary) + set(DICT_GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}) + diff --git a/opencc.spec b/opencc.spec new file mode 100644 index 0000000..46d2649 --- /dev/null +++ b/opencc.spec @@ -0,0 +1,71 @@ +Name: opencc +Version: 1.0.5 +Release: 4 +Summary: Simplified Chinese Traditional Conversion Library +License: ASL 2.0 +URL: https://github.com/BYVoid/OpenCC +Source0: https://github.com/BYVoid/OpenCC/archive/ver.%{version}.tar.gz#/OpenCC-ver.%{version}.tar.gz +Patch0001: opencc-fixes-cmake.patch +Patch0002: opencc-check-bounds.patch + +Provides: %{name}-tools = %{version}-%{release} +Obsoletes: %{name}-tools < %{version}-%{release} +BuildRequires: gcc-c++ gettext cmake doxygen python3 + +%description +Opencc is for between Traditional Chinese and Simplified Chinese characters and phrases conversion library. + +%package devel +Summary: Development files for OpenCC +Requires: %{name} = %{version}-%{release} + +%description devel +This package contains libraries and header files for developing applications that use opencc. + +%package help +Summary: Documentation for opencc +Requires: %{name} = %{version}-%{release} +Provides: %{name}-doc = %{version}-%{release} +Obsoletes: %{name}-doc < %{version}-%{release} + +%description help +This package provides documentation for opencc. + +%prep +%autosetup -n OpenCC-ver.%{version} -p1 + +%build +%cmake . -DENABLE_GETTEXT:BOOL=ON -DBUILD_DOCUMENTATION:BOOL=ON +%make_build VERBOSE=1 + +%install +%make_install + +%check +ctest + +%post +/sbin/ldconfig + +%postun +/sbin/ldconfig + +%files +%doc AUTHORS LICENSE README.md +%{_libdir}/lib*.so.* +%{_datadir}/opencc/ +%{_bindir}/* +%exclude %{_datadir}/opencc/doc +%exclude %{_libdir}/*.a + +%files devel +%{_includedir}/* +%{_libdir}/*.so +%{_libdir}/pkgconfig/*.pc + +%files help +%{_datadir}/opencc/doc + +%changelog +* Thu Dec 12 2019 fengbing - 1.0.5-4 +- Package init