Name:           openjpeg2
Version:        2.3.1
Release:        15
Summary:        C-Library for JPEG 2000
License:        BSD and MIT
URL:            https://github.com/uclouvain/openjpeg
Source0:        https://github.com/uclouvain/openjpeg/archive/v%{version}/openjpeg-%{version}.tar.gz

Patch1:         openjpeg2_opj2.patch

Patch6000:	CVE-2016-10505.patch
Patch6001:	CVE-2016-7445.patch
Patch6002:      CVE-2020-15389.patch
Patch6003:      backport-avoid-integer-overflow.patch
Patch6004:      backport-CVE-2020-27814.patch
Patch6005:      backport-CVE-2020-27841.patch
Patch6006:      backport-CVE-2020-27843.patch
Patch6007:      backport-CVE-2020-27845.patch
Patch6008:      backport-CVE-2020-8112.patch
Patch6009:      backport-CVE-2020-6851.patch
Patch6010:      backport-CVE-2020-27823.patch
Patch6011:      backport-CVE-2020-27824.patch
Patch6012:      backport-CVE-2021-29338.patch
Patch6013:      backport-CVE-2020-27842.patch
Patch6014:      backport-0001-CVE-2019-12973.patch
Patch6015:      backport-0002-CVE-2019-12973.patch
Patch6016:      backport-CVE-2021-3575.patch
Patch6017:      backport-CVE-2022-1122.patch
Patch6018:      backport-CVE-2023-39328.patch
Patch6019:      backport-CVE-2024-56826.patch
Patch6020:      backport-CVE-2024-56827.patch
 
BuildRequires:  cmake gcc-c++ make zlib-devel libpng-devel libtiff-devel lcms2-devel doxygen

Provides:       %{name}-tools
Obsoletes:      %{name}-tools

%description
OpenJPEG is an open-source JPEG 2000 codec written in C language. It has been developed in order
to promote the use of JPEG 2000, a still-image compression standard from the Joint Photographic
Experts Group (JPEG). Since April 2015, it is officially recognized by ISO/IEC and ITU-T as a
JPEG 2000 Reference Software.

%package        devel
Summary:        Development files for OpenJPEG 2
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description    devel
The %{name}-devel package contains libraries and header files for developing
applications that use OpenJPEG 2.

%package_help

%prep
%autosetup -n openjpeg-%{version} -p1 

# Remove all third party libraries just to be sure
find thirdparty/ -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} \;

%build
mkdir %{_target_platform}
pushd %{_target_platform}
%cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPENJPEG_INSTALL_LIB_DIR=%{_lib} \
    %{?optional_components:-DBUILD_MJ2=ON -DBUILD_JPWL=ON -DBUILD_JPIP=ON -DBUILD_JP3D=ON} \
    -DBUILD_DOC=ON \
    -DBUILD_STATIC_LIBS=OFF \
    -DBUILD_SHARED_LIBS=ON \
    %{?runcheck:-DBUILD_TESTING:BOOL=ON -DOPJ_DATA_ROOT=$PWD/../data} \
    ..
popd

%make_build VERBOSE=1 -C %{_target_platform}


%install
%make_install -C %{_target_platform}

mv %{buildroot}%{_mandir}/man1/opj_compress.1 %{buildroot}%{_mandir}/man1/opj2_compress.1
mv %{buildroot}%{_mandir}/man1/opj_decompress.1 %{buildroot}%{_mandir}/man1/opj2_decompress.1
mv %{buildroot}%{_mandir}/man1/opj_dump.1 %{buildroot}%{_mandir}/man1/opj2_dump.1

%ldconfig_scriptlets

%files
%defattr(-,root,root)
%{!?_licensedir:%global license %doc}
%doc AUTHORS.md
%license LICENSE
%{_libdir}/libopenjp2.so.*
%{_bindir}/opj2*
%exclude %{_datadir}/doc/

%files devel
%defattr(-,root,root)
%{_includedir}/openjpeg-2.3/*.h
%{_libdir}/*.so
%{_libdir}/openjpeg-2.3/
%{_libdir}/pkgconfig/libopenjp2.pc

%files help
%defattr(-,root,root)
%doc %{_target_platform}/doc/html
%doc NEWS.md README.md THANKS.md
%{_mandir}/man1/*.1*
%{_mandir}/man3/*.3*

%changelog
* Tue Jan 7 2025 changtao <changtao@kylinos.cn> - 2.3.1-15
- Type: CVE
- CVE: CVE-2024-56827
- SUG: NA
- DESC: fix CVE-2024-56827

* Tue Jan 7 2025 zhangpan <zhangpan103@h-partners.com> - 2.3.1-14
- fix CVE-2024-56826

* Tue Oct 29 2024 zhangpan <zhangpan103@h-partners.com> - 2.3.1-13
- fix CVE-2021-3575

* Thu Jul 11 2024 xinghe <xinghe2@h-partners.com> - 2.3.1-12
- Type:cves
- ID:CVE-2023-39328
- SUG:NA
- DESC:fix CVE-2023-39328

* Mon May 16 2022 dongyuzhen <dongyuzhen@h-partners.com> - 2.3.1-11
- fix CVE-2022-1122

* Tue Apr 12 2022 dongyuzhen <dongyuzhen@h-partners.com> - 2.3.1-10
- fix the issue of opj2_compress/opj2_decompress don't work with png/tiff images

* Mon Mar 14 2022 dongyuzhen <dongyuzhen@h-partners.com> - 2.3.1-9
- fix CVE-2019-12973,CVE-2021-3575

* Tue Jan 4 2022 dongyuzhen <dongyuzhen@huawei.com> - 2.3.1-8
- fix CVE-2020-27842

* Fri Sep 24 2021 yangcheng <yangcheng87@huawei.com> - 2.3.1-7
- fix CVE-2021-29338

* Tue Jun 8 2021 liuyumeng <liuyumeng5@huawei.com> - 2.3.1-6
- fix CVE-2020-8112 CVE-2020-6851 CVE-2020-27823 CVE-2020-27824,avoid integer overflow:pre-patch of CVE-2020-27841,fix fuzz

* Tue Feb 23 2021 jinzhimin <jinzhimin2@huawei.com> - 2.3.1-5
- fix CVE-2020-27841 CVE-2020-27843 CVE-2020-27845

* Sat Feb 20 2021 jinzhimin <jinzhimin2@huawei.com> - 2.3.1-4
- fix CVE-2020-27814

* Sat Jul 25 2020 zhangnaru <zhangnaru@huawei.com> -2.3.1-3
- fix CVE-2020-15389 

* Thu Sep 19 2019 openEuler Buildteam <buildteam@openeuler.org> - 2.3.1-2
- fix CVE-2016-10505 and CVE-2016-7445

* Thu Sep 19 2019 openEuler Buildteam <buildteam@openeuler.org> - 2.3.1-1
- Package init
