diff --git a/mupdf-1.21.1-fix-png_write_band.patch b/mupdf-1.21.1-fix-png_write_band.patch new file mode 100644 index 0000000000000000000000000000000000000000..65f49b5fac6a3aace9b3f3a5c3881671f7e58ed2 --- /dev/null +++ b/mupdf-1.21.1-fix-png_write_band.patch @@ -0,0 +1,50 @@ +From: Mamoru TASAKA +Date: Sun, 18 Dec 2022 00:22:04 +0000 (+0900) +Subject: Bug 706227: png_write_band: initialize stream before calling deflateBound +X-Git-Url: http://git.ghostscript.com/?p=mupdf.git;a=commitdiff_plain;h=a76b4ed0d3a2c7e52bba2d6c10b44d11d5ade2fe + +Bug 706227: png_write_band: initialize stream before calling deflateBound + +zlib deflateBound manual says when calling this function, +stream should have been initialized via a call to deflateInit_() +or deflateInit2_(), so change so. + +Note that without this fix, "mutool draw -F png" segfaults on s390x, +perhaps on big endian, uninitialized bytes of a value (which is +not wholly initialized) is read, on the other hand, on little endian +initialized bytes of the value is read, so it happens not to cause +segfault. + +Fixes https://bugs.ghostscript.com/show_bug.cgi?id=706227 +--- + +diff --git a/source/fitz/output-png.c b/source/fitz/output-png.c +index 17279f913..979c75eeb 100644 +--- a/source/fitz/output-png.c ++++ b/source/fitz/output-png.c +@@ -236,6 +236,12 @@ png_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_st + if (usize > SIZE_MAX / band_height) + fz_throw(ctx, FZ_ERROR_GENERIC, "png data too large."); + usize *= band_height; ++ writer->stream.opaque = ctx; ++ writer->stream.zalloc = fz_zlib_alloc; ++ writer->stream.zfree = fz_zlib_free; ++ err = deflateInit(&writer->stream, Z_DEFAULT_COMPRESSION); ++ if (err != Z_OK) ++ fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); + writer->usize = usize; + /* Now figure out how large a buffer we need to compress into. + * deflateBound always expands a bit, and it's limited by being +@@ -245,12 +251,6 @@ png_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_st + writer->csize = UINT32_MAX; + writer->udata = Memento_label(fz_malloc(ctx, writer->usize), "png_write_udata"); + writer->cdata = Memento_label(fz_malloc(ctx, writer->csize), "png_write_cdata"); +- writer->stream.opaque = ctx; +- writer->stream.zalloc = fz_zlib_alloc; +- writer->stream.zfree = fz_zlib_free; +- err = deflateInit(&writer->stream, Z_DEFAULT_COMPRESSION); +- if (err != Z_OK) +- fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); + } + + dp = writer->udata; diff --git a/mupdf-1.21.1-source.tar.gz b/mupdf-1.21.1-source.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..d449f20339320033c8d9592ef51dd3c8e89c2dbd Binary files /dev/null and b/mupdf-1.21.1-source.tar.gz differ diff --git a/mupdf-gl.desktop b/mupdf-gl.desktop new file mode 100644 index 0000000000000000000000000000000000000000..21dcc6eb38f0919c468f0add2c76c9dcf326e697 --- /dev/null +++ b/mupdf-gl.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Mupdf-GL +GenericName=PDF file viewer +Comment=Lightweight PDF file viewer written on portable C +Exec=mupdf-gl %f +Icon=mupdf-gl +Terminal=false +Type=Application +Categories=Viewer;Graphics; +MimeType=application/pdf;application/x-pdf; diff --git a/mupdf.desktop b/mupdf.desktop new file mode 100644 index 0000000000000000000000000000000000000000..7b01b903df14f011866f3274c9719a84cae0e8f6 --- /dev/null +++ b/mupdf.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Name=Mupdf +GenericName=PDF file viewer +Comment=Lightweight PDF file viewer written on portable C +Exec=mupdf-x11 %f +Icon=mupdf +Terminal=false +Type=Application +Categories=Viewer;Graphics; +MimeType=application/pdf;application/x-pdf; +NoDisplay=true diff --git a/mupdf.spec b/mupdf.spec new file mode 100644 index 0000000000000000000000000000000000000000..c823ded65fdce95ef5c93984b207341a306e6881 --- /dev/null +++ b/mupdf.spec @@ -0,0 +1,137 @@ +%define anolis_release 1 + +# Desired jbig2dec header files and library version +# Apparantly, jbig2dec complains even about newer versions. +# Please update if needed. +%global jbig2dec_version 0.19 +%global upversion %{version} + +Name: mupdf +Version: 1.21.1 +Release: %{anolis_release}%{?dist} +Summary: A lightweight PDF viewer and toolkit +License: AGPL-3.0-or-later +URL: http://mupdf.com/ +Source0: http://mupdf.com/downloads/archive/%{name}-%{upversion}-source.tar.gz +Source1: %{name}.desktop +Source2: %{name}-gl.desktop + +Patch: mupdf-1.21.1-fix-png_write_band.patch + +BuildRequires: gcc gcc-c++ make binutils desktop-file-utils coreutils pkgconfig +BuildRequires: openjpeg2-devel desktop-file-utils +BuildRequires: libjpeg-devel freetype-devel libXext-devel curl-devel +BuildRequires: harfbuzz-devel openssl-devel mesa-libEGL-devel +BuildRequires: mesa-libGL-devel mesa-libGLU-devel libXi-devel libXrandr-devel +BuildRequires: gumbo-parser-devel leptonica-devel tesseract-devel +BuildRequires: jbig2dec-devel = %{jbig2dec_version} +BuildRequires: jbig2dec-libs = %{jbig2dec_version} +Requires: jbig2dec-libs = %{jbig2dec_version} +# We need to build against the Artifex fork of lcms2 so that we are thread safe +# . Artifex make sure to rebase against upstream, who refuse +# to integrate Artifex's changes. +Provides: bundled(lcms2-devel) = 2.14~rc1^59-g88b6a72 +# We need to build against the Artifex fork of freeglut so that we are unicode safe. +Provides: bundled(freeglut-devel) = 3.0.0^11.g13ae6aa +# muPDF needs the muJS sources for the build even if we build against the system +# version so bundling them is the safer choice. +Provides: bundled(mujs-devel) = 1.3.2 +# muPDF builds only against in-tree extract which is versioned along with ghostpdl. +Provides: bundled(extract) = 9.56.0^53-gc18d9f3 + +%description +MuPDF is a lightweight PDF viewer and toolkit written in portable C. +The renderer in MuPDF is tailored for high quality anti-aliased +graphics. MuPDF renders text with metrics and spacing accurate to +within fractions of a pixel for the highest fidelity in reproducing +the look of a printed page on screen. +MuPDF has a small footprint. A binary that includes the standard +Roman fonts is only one megabyte. A build with full CJK support +(including an Asian font) is approximately seven megabytes. +MuPDF has support for all non-interactive PDF 1.7 features, and the +toolkit provides a simple API for accessing the internal structures of +the PDF document. Example code for navigating interactive links and +bookmarks, encrypting PDF files, extracting fonts, images, and +searchable text, and rendering pages to image files is provided. + +%package devel +Summary: Development files for %{name} +Requires: %{name} = %{version}-%{release} +Provides: %{name}-static = %{version}-%{release} + +%description devel +The mupdf-devel package contains header files for developing +applications that use mupdf and static libraries + +%package doc +Summary: Documentation files for %{name} +Requires: %{name} = %{version}-%{release} +BuildArch: noarch + +%description doc +The %{name}-doc package contains documentation files for %{name}. + +%prep +%autosetup -p1 -n %{name}-%{upversion}-source +for d in $(ls thirdparty | grep -v -e extract -e freeglut -e lcms2 -e mujs) +do + rm -rf thirdparty/$d +done + +echo > user.make "\ + USE_SYSTEM_FREETYPE := yes + USE_SYSTEM_HARFBUZZ := yes + USE_SYSTEM_JBIG2DEC := yes + USE_SYSTEM_JPEGXR := yes # not used without HAVE_JPEGXR + USE_SYSTEM_LCMS2 := no # need lcms2-art fork + USE_SYSTEM_LIBJPEG := yes + USE_SYSTEM_MUJS := no # build needs source anyways + USE_SYSTEM_OPENJPEG := yes + USE_SYSTEM_ZLIB := yes + USE_SYSTEM_GLUT := no # need freeglut2-art fork + USE_SYSTEM_CURL := yes + USE_SYSTEM_GUMBO := yes + USE_TESSERACT := yes + USE_SYSTEM_LEPTONICA := yes + USE_SYSTEM_TESSERACT := yes +" + +%build +export XCFLAGS="%{optflags} -fPIC -DJBIG_NO_MEMENTO -DTOFU -DTOFU_CJK_EXT" + +make %{?_smp_mflags} build=debug verbose=yes + +%install +make DESTDIR=%{buildroot} install prefix=%{_prefix} libdir=%{_libdir} build=debug verbose=yes +## handle docs on our own +rm -rf %{buildroot}/%{_docdir} +desktop-file-install --dir=%{buildroot}%{_datadir}/applications %{SOURCE1} +desktop-file-install --dir=%{buildroot}%{_datadir}/applications %{SOURCE2} +mkdir -p %{buildroot}%{_datadir}/icons/hicolor/scalable/apps +install -p -m644 docs/logo/mupdf-logo.svg %{buildroot}%{_datadir}/icons/hicolor/scalable/apps/mupdf.svg +install -p -m644 docs/logo/mupdf-logo.svg %{buildroot}%{_datadir}/icons/hicolor/scalable/apps/mupdf-gl.svg +## fix strange permissons +chmod 0644 %{buildroot}%{_libdir}/*.a +find %{buildroot}/%{_mandir} -type f -exec chmod 0644 {} \; +find %{buildroot}/%{_includedir} -type f -exec chmod 0644 {} \; +cd %{buildroot}/%{_bindir} && ln -s %{name}-x11 %{name} + +%generate_compatibility_deps + +%files +%license COPYING +%{_bindir}/* +%{_datadir}/applications/mupdf*.desktop +%{_datadir}/icons/hicolor/*/apps/* +%{_mandir}/man1/*.1* + +%files devel +%{_includedir}/%{name} +%{_libdir}/lib%{name}*.a + +%files doc +%doc README CHANGES docs/* + +%changelog +* Fri Mar 17 2023 happy_orange - 1.21.1-1 +- package init from upstream