diff --git a/pkgs/applications/misc/k2pdfopt/default.nix b/pkgs/applications/misc/k2pdfopt/default.nix index 015ef8760648..1cab20baef15 100644 --- a/pkgs/applications/misc/k2pdfopt/default.nix +++ b/pkgs/applications/misc/k2pdfopt/default.nix @@ -1,5 +1,5 @@ { stdenv, fetchzip, fetchurl, fetchpatch, cmake, pkgconfig -, zlib, libpng +, zlib, libpng, openjpeg , enableGSL ? true, gsl , enableGhostScript ? true, ghostscript , enableMuPDF ? true, mupdf @@ -40,11 +40,7 @@ stdenv.mkDerivation rec { # Patches from previous 1.10a version in nixpkgs patches = [ # Compatibility with new openjpeg - (fetchpatch { - name = "mupdf-1.9a-openjpeg-2.1.1.patch"; - url = "https://git.archlinux.org/svntogit/community.git/plain/mupdf/trunk/0001-mupdf-openjpeg.patch?id=5a28ad0a8999a9234aa7848096041992cc988099"; - sha256 = "1i24qr4xagyapx4bijjfksj4g3bxz8vs5c2mn61nkm29c63knp75"; - }) + ./load-jpx.patch (fetchurl { name = "CVE-2017-5896.patch"; @@ -64,6 +60,14 @@ stdenv.mkDerivation rec { # Don't remove mujs because upstream version is incompatible rm -rf thirdparty/{curl,freetype,glfw,harfbuzz,jbig2dec,jpeg,openjpeg,zlib} ''; + postPatch = let + # OpenJPEG version is hardcoded in package source + openJpegVersion = with stdenv; + lib.concatStringsSep "." (lib.lists.take 2 + (lib.splitString "." (lib.getVersion openjpeg))); + in '' + sed -i "s/__OPENJPEG__VERSION__/${openJpegVersion}/" source/fitz/load-jpx.c + ''; }); leptonica_modded = leptonica.overrideAttrs (attrs: { prePatch = '' diff --git a/pkgs/applications/misc/k2pdfopt/load-jpx.patch b/pkgs/applications/misc/k2pdfopt/load-jpx.patch new file mode 100644 index 000000000000..02a3799d040a --- /dev/null +++ b/pkgs/applications/misc/k2pdfopt/load-jpx.patch @@ -0,0 +1,29 @@ +--- a/source/fitz/load-jpx.c ++++ b/source/fitz/load-jpx.c +@@ -484,12 +484,16 @@ + /* Without the definition of OPJ_STATIC, compilation fails on windows + * due to the use of __stdcall. We believe it is required on some + * linux toolchains too. */ ++#ifdef __cplusplus ++extern "C" ++{ + #define OPJ_STATIC + #ifndef _MSC_VER + #define OPJ_HAVE_STDINT_H + #endif ++#endif + +-#include ++#include + + /* OpenJPEG does not provide a safe mechanism to intercept + * allocations. In the latest version all allocations go +@@ -971,4 +975,8 @@ + fz_drop_pixmap(ctx, img); + } + ++#ifdef __cplusplus ++} ++#endif ++ + #endif /* HAVE_LURATECH */