code:
diff -Nur recode-3.6-old/src/argmatch.c recode-3.6/src/argmatch.c
--- recode-3.6-old/src/argmatch.c	2008-05-27 15:17:09.000000000 +0300
+++ recode-3.6/src/argmatch.c	2008-05-27 15:18:30.000000000 +0300
@@ -18,6 +18,8 @@
 /* Written by David MacKenzie <djm@ai.mit.edu>
    Modified by Akim Demaille <demaille@inf.enst.fr> */

+#include <stdlib.h>
+
 #include "argmatch.h"

 #include <stdio.h>

repo_name: ayhanyalcinsoy/main


code:
diff -Naur recode-3.6-orig/Makefile.am recode-3.6/Makefile.am
--- recode-3.6-orig/Makefile.am	2009-05-15 14:31:12.463908436 +0300
+++ recode-3.6/Makefile.am	2009-05-15 14:31:31.540660383 +0300
@@ -18,7 +18,7 @@
 # 02111-1307, USA.

 AUTOMAKE_OPTIONS = gnits
-ACLOCAL = ./aclocal.sh @ACLOCAL@
+ACLOCAL = /usr/bin/aclocal
 ACLOCAL_AMFLAGS = -I m4

 BABYL = ../rmail/* ../*/rmail/* ../*/*/RMAIL ../*/*/rmail/*


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>recode</Name>
        <Homepage>http://www.gnu.org/software/recode/</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>GPLv2</License>
        <IsA>app:console</IsA>
        File character set converter
        <Description>Recode can convert files to various character sets (e.g. utf8, iso-8859-1, koi8r..).</Description>
        <Archive sha1sum="53fdab85241c47dcc079fe4290335b991edc74b5" type="targz">https://github.com/rrthomas/recode/releases/download/v3.7/recode-3.7.tar.gz</Archive>
        <BuildDependencies>
            <Dependency>gettext</Dependency>
            <Dependency>texinfo</Dependency>
        </BuildDependencies>
        <Patches>

        </Patches>
    </Source>

    <Package>
        <Name>recode</Name>
        <Files>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="info">/usr/share/info</Path>
            <Path fileType="man">/usr/share/man</Path>
            <Path fileType="localedata">/usr/share/locale</Path>
        </Files>
    </Package>

    <Package>
        <Name>recode-devel</Name>
        Development files for recode
        <RuntimeDependencies>
            <Dependency release="current">recode</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="header">/usr/include</Path>
        </Files>
    </Package>

    <History>
        <Update release="4">
            <Date>2018-02-11</Date>
            <Version>3.7</Version>
            <Comment>Version Bump.</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="3">
            <Date>2017-03-02</Date>
            <Version>3.6</Version>
            <Comment>Rebuild for new toolchain.</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-06-09</Date>
            <Version>3.6</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2016-01-01</Date>
            <Version>3.6</Version>
            <Comment>First release</Comment>
            <Name>Stefan Gronewold</Name>
            <Email>groni@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>recode</Name>
        Karakter kümesi dönüşümü aracı
        <Description xml:lang="tr">Recode dosyaların bir karakter kümesinden bir başkasına dönüştürülmesine imkân verir. Çok sayıda karakter kümesini destekler.</Description>
    </Source>

    <Package>
        <Name>recode-devel</Name>
        recode için geliştirme dosyaları
    </Package>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import cmaketools
from pisi.actionsapi import pisitools
from pisi.actionsapi import autotools
from pisi.actionsapi import get

def setup():

    pisitools.dosed("CMakeLists.txt", "\"share\/doc\/\$\{MAIN_DIR_NAME\}.*", "\"share/doc/${MAIN_DIR_NAME}/\")")

    cmaketools.configure("-DWANT_DISTROBUILD=YES \
                          -DWANT_QT5SUPPORT=ON")

def build():

    cmaketools.make()

def install():

    autotools.rawInstall("DESTDIR=%s" % get.installDIR())

    pisitools.insinto("/usr/share/applications", "scribus.desktop")
    pisitools.insinto("/usr/share/pixmaps", "resources/iconsets/1_5_1/scribus.png")
    pisitools.insinto("/usr/share/pixmaps", "resources/iconsets/1_5_0/scribusdoc.png", "x-scribus.png")


code:
#!/usr/bin/python

import os

def postInstall(fromVersion, fromRelease, toVersion, toRelease):
    update-mime-database usr/share/mime > /dev/null 2>&1
    update-desktop-database -q > /dev/null 2>&1


code:
diff -Naur scribus-1.3.6.orig/scribus/plugins/gettext/htmlim/CMakeLists.txt scribus-1.3.6/scribus/plugins/gettext/htmlim/CMakeLists.txt
--- scribus-1.3.6.orig/scribus/plugins/gettext/htmlim/CMakeLists.txt	2007-09-30 22:55:37.000000000 +0300
+++ scribus-1.3.6/scribus/plugins/gettext/htmlim/CMakeLists.txt	2010-05-17 16:39:49.842776114 +0300
@@ -18,7 +18,7 @@

 ADD_LIBRARY(${SCRIBUS_HTML_GT_PLUGIN} MODULE ${HTML_GT_PLUGIN_SOURCES} ${HTML_GT_PLUGIN_MOC_SOURCES})

-target_link_libraries(${SCRIBUS_HTML_GT_PLUGIN} ${PLUGIN_LIBRARIES})
+target_link_libraries(${SCRIBUS_HTML_GT_PLUGIN} ${PLUGIN_LIBRARIES} ${LIBXML2_LIBRARIES} ${ZLIB_LIBRARIES})

 INSTALL(TARGETS ${SCRIBUS_HTML_GT_PLUGIN}
   LIBRARY
diff -Naur scribus-1.3.6.orig/scribus/plugins/gettext/odtim/CMakeLists.txt scribus-1.3.6/scribus/plugins/gettext/odtim/CMakeLists.txt
--- scribus-1.3.6.orig/scribus/plugins/gettext/odtim/CMakeLists.txt	2007-09-30 22:55:37.000000000 +0300
+++ scribus-1.3.6/scribus/plugins/gettext/odtim/CMakeLists.txt	2010-05-17 16:40:13.467775741 +0300
@@ -20,7 +20,7 @@

 ADD_LIBRARY(${SCRIBUS_ODT_IM_PLUGIN} MODULE ${ODT_IM_PLUGIN_SOURCES} ${ODT_IM_PLUGIN_MOC_SOURCES})

-target_link_libraries(${SCRIBUS_ODT_IM_PLUGIN} ${PLUGIN_LIBRARIES})
+target_link_libraries(${SCRIBUS_ODT_IM_PLUGIN} ${PLUGIN_LIBRARIES} ${LIBXML2_LIBRARIES} ${ZLIB_LIBRARIES})

 INSTALL(TARGETS ${SCRIBUS_ODT_IM_PLUGIN}
   LIBRARY


code:
--- scribus/prefsmanager.cpp	2006-07-29 02:29:59.000000000 +0300
+++ scribus/prefsmanager.cpp.new	2006-10-07 22:25:58.000000000 +0300
@@ -117,7 +117,7 @@
 	bool goodFont = false;
 	for ( SCFontsIterator itf(appPrefs.AvailFonts); itf.current(); ++itf)
 	{
-		if ((itf.currentKey() == "Arial Regular") || (itf.currentKey() == "Times New Roman Regular"))
+		if ((itf.currentKey() == "Arial Regular") || (itf.currentKey() == "Times New Roman Regular") || (itf.currentKey() == "Nimbus Roman No9 L Regular"))
 		{
 			appPrefs.toolSettings.defFont = itf.currentKey();
 			goodFont = true;


code:
Description: Fix case of "OpenSSL" to match the case of the file shipped by cmake
Author: Mattia Rizzolo <mattia@debian.org>
Last-Update: 2017-06-05

--- a/cmake/modules/FindLIBPODOFO.cmake
+++ b/cmake/modules/FindLIBPODOFO.cmake
@@ -45,7 +45,7 @@
 	#message(STATUS "PODOFO PATCH VERSION ${PODOFO_PATCH_VER}")
 	set(LIBPODOFO_VERSION "${PODOFO_MAJOR_VER}.${PODOFO_MINOR_VER}.${PODOFO_PATCH_VER}" CACHE STRING "PoDoFo version string")
 	if(LIBPODOFO_VERSION VERSION_GREATER "0.9.4")
-		find_package(OPENSSL)
+		find_package(OpenSSL)
 		if (OPENSSL_FOUND)
 			message("OpenSSL found OK for installed version of PoDoFo (>= 0.9.5) - Enabling support for PDF embedded in AI")
 			set(LIBPODOFO_FOUND TRUE CACHE BOOLEAN "Was libpodofo found")


code:
 scribus/sclayer.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scribus/sclayer.cpp b/scribus/sclayer.cpp
index 502112b..4da7bd5 100644
--- a/scribus/sclayer.cpp
+++ b/scribus/sclayer.cpp
@@ -9,6 +9,7 @@ for which a new license (GPL+exception) is in place.

 #include <QHash>   //necessary to avoid msvc warnings induced by SCRIBUS_API on ScLayers + early instanciation of templates
 #include <QVector> //necessary to avoid msvc warnings induced by SCRIBUS_API on ScLayers + early instanciation of templates
+#include <QObject>
 #include <QtAlgorithms>

 ScLayer::ScLayer(void)


code:
 CMakeLists.txt                              | 8 ++++++++
 scribus/colormgmt/CMakeLists.txt            | 2 ++
 scribus/desaxe/CMakeLists.txt               | 1 +
 scribus/fonts/CMakeLists.txt                | 1 +
 scribus/styles/CMakeLists.txt               | 2 ++
 scribus/text/CMakeLists.txt                 | 1 +
 scribus/third_party/lib2geom/CMakeLists.txt | 8 +-------
 scribus/third_party/zip/CMakeLists.txt      | 2 ++
 8 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 29d66f3..62d145f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -131,6 +131,14 @@ IF (_machine_sparc64)
 	SET(ARCH64BIT 1)
 ENDIF (_machine_sparc64)

+# We need to pass -fPIC to lib2geom on amd64, mips, mipsel, and hppa. See:
+# http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3 and
+# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=559133
+
+IF (ARCH_X86_64 EQUAL 1 OR ARCH_HPPA EQUAL 1 OR ARCH_MIPS EQUAL 1 OR ARCH_MIPS_64 EQUAL 1 OR ARCH_PPC_64 EQUAL 1)
+	SET(CMAKE_CXX_FLAGS_FPIC "-fPIC")
+ENDIF (ARCH_X86_64 EQUAL 1 OR ARCH_HPPA EQUAL 1 OR ARCH_MIPS EQUAL 1 OR ARCH_MIPS_64 EQUAL 1 OR ARCH_PPC_64 EQUAL 1)
+
 ## Do our Apple OSX version setup
 IF (APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND (ARCH_X86 EQUAL 1 OR ARCH_X86_64 EQUAL 1))
 	STRING(REGEX REPLACE ".*-darwin([0-9]+).*" "\\1" _apple_ver "${MACHINE}")
diff --git a/scribus/colormgmt/CMakeLists.txt b/scribus/colormgmt/CMakeLists.txt
index 7298a28..87c4f5e 100644
--- a/scribus/colormgmt/CMakeLists.txt
+++ b/scribus/colormgmt/CMakeLists.txt
@@ -3,6 +3,8 @@ ${CMAKE_SOURCE_DIR}
 ${CMAKE_SOURCE_DIR}/scribus
 )

+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_FPIC}")
+
 INCLUDE_DIRECTORIES( ${LCMS2_INCLUDE_DIR} )
 SET(SCRIBUS_LCMS_IMPL_SOURCES
 	sclcms2colormgmtengineimpl.cpp
diff --git a/scribus/desaxe/CMakeLists.txt b/scribus/desaxe/CMakeLists.txt
index 0098028..85e76b6 100644
--- a/scribus/desaxe/CMakeLists.txt
+++ b/scribus/desaxe/CMakeLists.txt
@@ -4,6 +4,7 @@ ${CMAKE_SOURCE_DIR}/scribus
 ${FREETYPE_INCLUDE_DIRS}
 )

+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_FPIC}")

 SET(SCRIBUS_DESAXE_LIB_SOURCES
 saxXML.cpp
diff --git a/scribus/fonts/CMakeLists.txt b/scribus/fonts/CMakeLists.txt
index 799e102..f04c680 100644
--- a/scribus/fonts/CMakeLists.txt
+++ b/scribus/fonts/CMakeLists.txt
@@ -4,6 +4,7 @@ ${CMAKE_SOURCE_DIR}/scribus
 ${FREETYPE_INCLUDE_DIRS}
 )

+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_FPIC}")

 SET(SCRIBUS_FONTS_LIB_SOURCES
   scface.cpp
diff --git a/scribus/styles/CMakeLists.txt b/scribus/styles/CMakeLists.txt
index 6e0cf0a..2839689 100644
--- a/scribus/styles/CMakeLists.txt
+++ b/scribus/styles/CMakeLists.txt
@@ -4,6 +4,8 @@ INCLUDE_DIRECTORIES(
 	${FREETYPE_INCLUDE_DIRS}
 )

+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_FPIC}")
+
 SET(SCRIBUS_STYLES_MOC_CLASSES
 )

diff --git a/scribus/text/CMakeLists.txt b/scribus/text/CMakeLists.txt
index 1cd112f..4f658e3 100644
--- a/scribus/text/CMakeLists.txt
+++ b/scribus/text/CMakeLists.txt
@@ -4,6 +4,7 @@ INCLUDE_DIRECTORIES(
 	${FREETYPE_INCLUDE_DIRS}
 )

+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_FPIC}")

 SET(SCRIBUS_TEXT_MOC_CLASSES
 	storytext.h
diff --git a/scribus/third_party/lib2geom/CMakeLists.txt b/scribus/third_party/lib2geom/CMakeLists.txt
index 6187d96..3106f6e 100755
--- a/scribus/third_party/lib2geom/CMakeLists.txt
+++ b/scribus/third_party/lib2geom/CMakeLists.txt
@@ -5,13 +5,7 @@ ${CMAKE_SOURCE_DIR}/scribus

 SET(2GEOM_VERSION 0.1.0)

-# We need to pass -fPIC to lib2geom on amd64, mips, mipsel, and hppa. See:
-# http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3 and
-# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=559133
-
-IF (ARCH_X86_64 EQUAL 1 OR ARCH_HPPA EQUAL 1 OR ARCH_MIPS EQUAL 1 OR ARCH_MIPS_64 EQUAL 1 OR ARCH_PPC_64 EQUAL 1)
-  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
-ENDIF (ARCH_X86_64 EQUAL 1 OR ARCH_HPPA EQUAL 1 OR ARCH_MIPS EQUAL 1 OR ARCH_MIPS_64 EQUAL 1 OR ARCH_PPC_64 EQUAL 1)
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_FPIC}")

 OPTION(2GEOM_BUILD_SHARED
   "Build lib2geom and libtoy as shared libraries."
diff --git a/scribus/third_party/zip/CMakeLists.txt b/scribus/third_party/zip/CMakeLists.txt
index edf9683..f7676ab 100644
--- a/scribus/third_party/zip/CMakeLists.txt
+++ b/scribus/third_party/zip/CMakeLists.txt
@@ -4,6 +4,8 @@ ${CMAKE_SOURCE_DIR}/scribus
 ${ZLIB_INCLUDE_DIR}
 )

+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_FPIC}")
+
 SET(SCRIBUS_ZIP_LIB_SOURCES
         unzip.cpp
         zip.cpp


code:
 CMakeLists.txt | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 29d66f3..1c08cdd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -244,19 +244,21 @@ else()
 endif()

 #SHARE - use the default on Apple as TAG_VERSION is empty
-if(WIN32 OR OS2)
-	set(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/")
-else()
-	if(TAG_VERSION OR BUILD_OSX_BUNDLE)
-		set(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${MAIN_DIR_NAME}${TAG_VERSION}/")
-	else()
-		if(NOT WANT_VERSIONING)
-			set(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${MAIN_DIR_NAME}/")
-		else()
-			set(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${MAIN_DIR_NAME}-${VERSION}/")
-		endif()
-	endif()
-endif()
+if(NOT DOCDIR)
+	if(WIN32 OR OS2)
+		set(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/")
+	else()
+		if(TAG_VERSION OR BUILD_OSX_BUNDLE)
+			set(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${MAIN_DIR_NAME}${TAG_VERSION}/")
+		else()
+			if(NOT WANT_VERSIONING)
+				set(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${MAIN_DIR_NAME}/")
+			else()
+				set(DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${MAIN_DIR_NAME}-${VERSION}/")
+			endif()
+		endif()
+	endif()
+endif()
 if(NOT IS_ABSOLUTE ${DOCDIR})
 	add_definitions("-DDOCDIR=\\\"${CMAKE_INSTALL_PREFIX}/${DOCDIR}\\\"")
 else()


code:
 scribus/third_party/prc/CMakeLists.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scribus/third_party/prc/CMakeLists.txt b/scribus/third_party/prc/CMakeLists.txt
index 5f7c2c6..1da7177 100644
--- a/scribus/third_party/prc/CMakeLists.txt
+++ b/scribus/third_party/prc/CMakeLists.txt
@@ -5,6 +5,8 @@ ${OPENGL_INCLUDE_DIR}
 ${FREETYPE_INCLUDE_DIRS}
 )

+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_FPIC}")
+
 set(SCRIBUS_PRC_LIB_SOURCES
     oPRCFile.cc
     PRCbitStream.cc


code:
--- scribus-0.8/scribus/scfonts.cpp.orig	Sun Sep 22 10:54:38 2002
+++ scribus-0.8/scribus/scfonts.cpp	Thu Oct 24 11:53:26 2002
@@ -463,6 +463,7 @@
 	char **fontpath=XGetFontPath(display,&pathcount);
 	for(i=0; i<pathcount; ++i)
 		AddPath(fontpath[i]);
+	AddPath("/usr/share/fonts/Type1");
 	XFreeFontPath(fontpath);
 }


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>scribus</Name>
        <Homepage>http://www.scribus.net/</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>GPLv2</License>
        <Icon>scribusicon</Icon>
        <IsA>app:gui</IsA>
        Desktop Publishing (DTP) and Layout program
        <Description>Scribus is an opensource desktop publishing application with features like CMYK colorspace and PDF output.
        </Description><Archive sha1sum="787d427e5e2c1b508e1b0a6cb9cba04075b9e5ca" type="tarxz">http://sourceforge.net/projects/scribus/files/scribus-devel/1.5.3/scribus-1.5.3.tar.xz</Archive>
        <BuildDependencies>
            <Dependency>cmake</Dependency>
            <Dependency>cups-devel</Dependency>
            <Dependency>desktop-file-utils</Dependency>
            <Dependency>lcms2-devel</Dependency>
            <Dependency>libart_lgpl-devel</Dependency>
            <Dependency>libjpeg-turbo-devel</Dependency>
            <Dependency>libpng-devel</Dependency>
            <Dependency>tiff-devel</Dependency>
            <Dependency>libxml2-devel</Dependency>
            <Dependency>openssl-devel</Dependency>
            <Dependency>python-devel</Dependency>
            <Dependency>ghostscript-devel</Dependency>
            <Dependency>gnutls-devel</Dependency>
            <Dependency>poppler-devel</Dependency>
            <Dependency>qt5-base-devel</Dependency>
            <Dependency>qt5-webkit-devel</Dependency>
            <Dependency>qt5-location-devel</Dependency>
            <Dependency>qt5-linguist</Dependency>
            <Dependency>zlib-devel</Dependency>
            <Dependency>freetype-devel</Dependency>
            <Dependency>gnutls-devel</Dependency>
            <Dependency>cairo-devel</Dependency>
            <Dependency>hunspell-devel</Dependency>
            <Dependency>boost-devel</Dependency>
            <Dependency>libwpg-devel</Dependency>
            <Dependency>podofo-devel</Dependency>
            <Dependency>libvisio-devel</Dependency>
            <Dependency>libcdr-devel</Dependency>
            <Dependency>GraphicsMagick-devel</Dependency>
            <Dependency>libpagemaker-devel</Dependency>
            <Dependency>harfbuzz-devel</Dependency>
        </BuildDependencies>
        <Patches>
            <Patch>scribus-1.5.3-docdir.patch</Patch>
            <Patch>findOpenSSL.patch</Patch>
            <Patch>scribus-1.5.3-fpic.patch</Patch>
            <Patch>PisiLinux-correctly_link_to_libxml2.patch</Patch>
            <Patch>scribus-standard-font-paths.patch</Patch>

        </Patches>
    </Source>

    <Package>
        <Name>scribus</Name>
        <RuntimeDependencies>
            <Dependency>icu4c</Dependency>
            <Dependency>cups</Dependency>
            <Dependency>tiff</Dependency>
            <Dependency>zlib</Dependency>
            <Dependency>cairo</Dependency>
            <Dependency>lcms2</Dependency>
            <Dependency>libgcc</Dependency>
            <Dependency>podofo</Dependency>
            <Dependency>python</Dependency>
            <Dependency>libxml2</Dependency>
            <Dependency>poppler</Dependency>
            <Dependency>freetype</Dependency>
            <Dependency>hunspell</Dependency>
            <Dependency>qt5-base</Dependency>
            <Dependency>fontconfig</Dependency>
            <Dependency>librevenge</Dependency>
            <Dependency>qt5-webkit</Dependency>
            <Dependency>libjpeg-turbo</Dependency>
            <Dependency>qt5-declarative</Dependency>
            <Dependency>libpagemaker</Dependency>
            <Dependency>libcdr</Dependency>
            <Dependency>GraphicsMagick</Dependency>
            <Dependency>libvisio</Dependency>
            <Dependency>libmspub</Dependency>
            <Dependency>harfbuzz</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="man">/usr/share</Path>
        </Files>
    </Package>

    <Package>
        <Name>scribus-docs</Name>
        Documentation files for scribus
        <Files>
            <Path fileType="doc">/usr/share/doc/scribus</Path>
        </Files>
    </Package>

    <History>
        <Update release="5">
            <Date>2018-02-03</Date>
            <Version>1.5.3</Version>
            <Comment>Rebuild.</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="4">
            <Date>2017-08-23</Date>
            <Version>1.5.3</Version>
            <Comment>Version bump</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="3">
            <Date>2017-04-17</Date>
            <Version>1.5.2</Version>
            <Comment>Rebuild with new toolchain</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-06-10</Date>
            <Version>1.5.2</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2016-05-18</Date>
            <Version>1.5.2</Version>
            <Comment>First release</Comment>
            <Name>Stefan Gronewold</Name>
            <Email>groni@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>scribus</Name>
        Masaüstü yayıncılık uygulaması
        <Description xml:lang="tr">Scribus, açık kaynak kodlu bir DTP (masaüstü yayıncılık) programıdır. Renk ayrımından PDF dönüşümlerine, PDF form elementleri yaratmadan Preflight Check gibi işlemlere kadar, profesyonel bir DTP paketinde bulabileceğiniz her fonksiyona sahiptir.</Description>
    </Source>

    <Package>
        <Name>scribus-docs</Name>
        scribus için belgelendirme dosyaları
    </Package>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import kde5
from pisi.actionsapi import pisitools

def setup():
    kde5.configure()

def build():
    kde5.make()

def install():
    kde5.install()

    pisitools.dodoc("AUTHORS", "CHANGELOG", "COPYING", "README")


code:
--- a/skgbasemodeler/skgdocument.cpp
+++ b/skgbasemodeler/skgdocument.cpp
@@ -42,7 +42,6 @@
 #include <qurl.h>

 #include <sqlite3.h>
-#include <math.h>
 #include <cmath>

 #include "skgtraces.h"
@@ -51,11 +50,6 @@
 #include "skgpropertyobject.h"
 #include "skgtransactionmng.h"
 #include "skgreport.h"
-
-#ifdef Q_OS_WIN
-#define isnan(a) _isnan(a)
-#define isinf(a) !_finite(a)
-#endif

 #ifdef SKGCIPHER
 #define SQLDRIVERNAME QStringLiteral("SKGSQLCIPHER")
@@ -2693,7 +2687,7 @@
     if (iValue > 0) {
         p = '+' % p;
     }
-    if (p.count() > 10 || isnan(iValue) || isinf(iValue)) {
+    if (p.count() > 10 || std::isnan(iValue) || std::isinf(iValue)) {
         p = QChar(8734);
     }
     return "<font color=\"" %

--- a/plugins/import/skrooge_import_gnc/skgimportplugingnc.cpp
+++ b/plugins/import/skrooge_import_gnc/skgimportplugingnc.cpp
@@ -27,7 +27,6 @@

 #include <qdom.h>
 #include <qfileinfo.h>
-#include <math.h>
 #include <cmath>

 #include "skgtraces.h"
@@ -36,11 +35,6 @@
 #include "skgobjectbase.h"
 #include "skgpayeeobject.h"
 #include "skgimportexportmanager.h"
-
-#ifdef Q_OS_WIN
-#define isnan(a) _isnan(a)
-#define isinf(a) !_finite(a)
-#endif

 /**
  * This plugin factory.
@@ -386,7 +380,7 @@
                                         }
                                     }

-                                    if (!isnan(info.value)) {
+                                    if (!std::isnan(info.value)) {
                                         QChar accountType = mapIdType[info.account.text()];
                                         if (accountType == 'C') {
                                             suboperationsList.push_front(info);


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>skrooge</Name>
        <Homepage>http://skrooge.org</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>GPLv3</License>
        <Icon>skrooge</Icon>
        <IsA>app:gui</IsA>
        <Summary>Personal finances manager</Summary>
        <Description>Skrooge allows you to manage your personal finances, powered by KDE. Thanks to its many features, it is one of the most powerful way to enter, follow, and analyze your expenses.</Description>
        <Archive sha1sum="4159a7e326cf69c90648a7d3bf8ad1ba752d8662" type="tarxz">mirrors://kde/stable/skrooge/skrooge-2.11.0.tar.xz</Archive>
        <BuildDependencies>
            <Dependency>qt5-base-devel</Dependency>
            <Dependency>extra-cmake-modules</Dependency>
            <Dependency>qt5-webkit-devel</Dependency>
            <Dependency>qt5-script-devel</Dependency>
            <Dependency>qt5-sql-mysql</Dependency>
            <Dependency>qt5-sql-odbc</Dependency>
            <Dependency>qt5-sql-postgresql</Dependency>
            <Dependency>qt5-sql-sqlite</Dependency>
            <Dependency>qt5-designer-devel</Dependency>
            <Dependency>qt5-svg-devel</Dependency>
            <Dependency>qt5-location-devel</Dependency>
            <Dependency>grantlee-qt5-devel</Dependency>
            <Dependency>karchive-devel</Dependency>
            <Dependency>kconfig-devel</Dependency>
            <Dependency>kcoreaddons-devel</Dependency>
            <Dependency>ki18n-devel</Dependency>
            <Dependency>kitemviews-devel</Dependency>
            <Dependency>kwidgetsaddons-devel</Dependency>
            <Dependency>kwindowsystem-devel</Dependency>
            <Dependency>kcompletion-devel</Dependency>
            <Dependency>kdoctools-devel</Dependency>
            <Dependency>kjobwidgets-devel</Dependency>
            <Dependency>kconfigwidgets-devel</Dependency>
            <Dependency>kdesignerplugin</Dependency>
            <Dependency>kiconthemes-devel</Dependency>
            <Dependency>kio-devel</Dependency>
            <Dependency>knewstuff-devel</Dependency>
            <Dependency>kparts-devel</Dependency>
            <Dependency>kwallet-devel</Dependency>
            <Dependency>kxmlgui-devel</Dependency>
            <Dependency>sqlcipher-devel</Dependency>
            <Dependency>qca2-qt5-devel</Dependency>
            <Dependency>kdelibs4-support-devel</Dependency>
            <Dependency>kemoticons-devel</Dependency>
            <Dependency>kitemmodels-devel</Dependency>
            <Dependency>kinit-devel</Dependency>
            <Dependency>kunitconversion-devel</Dependency>
            <Dependency>kactivities-devel</Dependency>
            <Dependency>knotifyconfig-devel</Dependency>
            <Dependency>krunner-devel</Dependency>
            <Dependency>libofx-devel</Dependency>
        </BuildDependencies>
        <Patches>
            <!--Patch level="1">skrooge-gcc-fix.patch</Patch-->
        </Patches>
    </Source>

    <Package>
        <Name>skrooge</Name>
        <RuntimeDependencies>
            <Dependency>kio</Dependency>
            <Dependency>ki18n</Dependency>
            <Dependency>kparts</Dependency>
            <Dependency>libgcc</Dependency>
            <Dependency>libofx</Dependency>
            <Dependency>kconfig</Dependency>
            <Dependency>krunner</Dependency>
            <Dependency>kwallet</Dependency>
            <Dependency>kxmlgui</Dependency>
            <Dependency>qt5-svg</Dependency>
            <Dependency>karchive</Dependency>
            <Dependency>kservice</Dependency>
            <Dependency>qca2-qt5</Dependency>
            <Dependency>qt5-base</Dependency>
            <Dependency>knewstuff</Dependency>
            <Dependency>sqlcipher</Dependency>
            <Dependency>kitemviews</Dependency>
            <Dependency>qt5-script</Dependency>
            <Dependency>qt5-webkit</Dependency>
            <Dependency>kcompletion</Dependency>
            <Dependency>kcoreaddons</Dependency>
            <Dependency>kdbusaddons</Dependency>
            <Dependency>kiconthemes</Dependency>
            <Dependency>grantlee-qt5</Dependency>
            <Dependency>ktextwidgets</Dependency>
            <Dependency>knotifyconfig</Dependency>
            <Dependency>kconfigwidgets</Dependency>
            <Dependency>knotifications</Dependency>
            <Dependency>kwidgetsaddons</Dependency>
            <Dependency>qt5-declarative</Dependency>
            <Dependency>kdelibs4-support</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="config">/etc/xdg</Path>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="data">/usr/share/appdata</Path>
            <Path fileType="data">/usr/share/applications</Path>
            <Path fileType="config">/usr/share/config.kcfg</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="data">/usr/share/icons</Path>
            <Path fileType="data">/usr/share/knotifications5</Path>
            <Path fileType="data">/usr/share/kservices5</Path>
            <Path fileType="data">/usr/share/kservicetypes5</Path>
            <Path fileType="data">/usr/share/kxmlgui5</Path>
            <Path fileType="localedata">/usr/share/locale</Path>
            <Path fileType="data">/usr/share/mime</Path>
            <Path fileType="data">/usr/share/skrooge</Path>
            <Path fileType="data">/usr/share/metainfo/org.kde.skrooge.appdata.xml</Path>
        </Files>
    </Package>

    <History>
        <Update release="6">
            <Date>2018-02-04</Date>
            <Version>2.11.0</Version>
            <Comment>Version bump</Comment>
            <Name>Ali Cengiz Kurt</Name>
            <Email>alicengizkurt@gmail.com</Email>
        </Update>
        <Update release="5">
            <Date>2017-10-09</Date>
            <Version>2.9.0</Version>
            <Comment>Version bump.</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="4">
            <Date>2017-07-08</Date>
            <Version>2.7.0</Version>
            <Comment>Release bump.</Comment>
            <Name>Kamil Atlı</Name>
            <Email>suvari@pisilinux.org</Email>
        </Update>
        <Update release="3">
            <Date>2017-01-23</Date>
            <Version>2.7.0</Version>
            <Comment>Version bump.</Comment>
            <Name>Stefan Gronewold(groni)</Name>
            <Email>groni@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-05-23</Date>
            <Version>2.4.0</Version>
            <Comment>Version bump</Comment>
            <Name>Alihan Öztürk</Name>
            <Email>alihan@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2016-03-22</Date>
            <Version>2.3.0</Version>
            <Comment>First release</Comment>
            <Name>Alihan Öztürk</Name>
            <Email>alihan@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>skrooge</Name>
        <Summary xml:lang="tr">Kişisel finansal yönetici</Summary>
        <Description xml:lang="tr">Skrooge, kişisel finans akışınızı kontrol altında tutmanızı sağlayan bir uygulamadır.</Description>
    </Source>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools

def setup():
    autotools.configure()

def install():
    autotools.install()

    pisitools.dodoc("AUTHORS", "ChangeLog", "COPYING", "NEWS", "README", "TODO")


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>texi2html</Name>
        <Homepage>http://savannah.nongnu.org/projects/texi2html/</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>GPLv2</License>
        <IsA>app:console</IsA>
        <Summary>Texinfo to HTML converter</Summary>
        <Description>texi2html is a Perl script which can generate HTML from Texinfo source files.</Description>
        <Archive sha1sum="20072444ce814d0e74fd7e467d1506908f8c889c" type="tarbz2">http://download.savannah.gnu.org/releases/texi2html/texi2html-5.0.tar.bz2</Archive>
    </Source>

    <Package>
        <Name>texi2html</Name>
        <Files>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="info">/usr/share/info</Path>
            <Path fileType="doc">/usr/share/doc/texi2html</Path>
            <Path fileType="man">/usr/share/man/man1</Path>
            <Path fileType="data">/usr/share/texi2html</Path>
            <Path fileType="data">/usr/share/texinfo</Path>
            <Path fileType="localedata">/usr/share/locale</Path>
        </Files>
    </Package>

    <History>
        <Update release="3">
            <Date>2017-02-18</Date>
            <Version>5.0</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-06-09</Date>
            <Version>5.0</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2014-05-20</Date>
            <Version>5.0</Version>
            <Comment>First release</Comment>
            <Name>Serdar Soytetir</Name>
            <Email>kaptan@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>texi2html</Name>
        <Summary xml:lang="tr">Texinfo'dan HTML'ye dönüştürücü</Summary>
        <Description xml:lang="tr">text2html Texinfo kaynak dosyalarından HTML çıktı üretebilen bir Perl betiğidir.</Description>
    </Source>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import pisitools

def install():
    pisitools.dobin("bookman")
    pisitools.dobin("src2man")
    pisitools.dobin("txt2man")

    pisitools.doman("*.1")

    pisitools.dodoc("Changelog", "README")


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>txt2man</Name>
        <Homepage>http://mvertes.free.fr/</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>GPLv2</License>
        <IsA>app:console</IsA>
        <Summary>A converter from flat ASCII text to man page format</Summary>
        <Description>txt2man converts flat ASCII text to man page format.</Description>
        <Archive sha1sum="ef1392785333ea88f7e01f4f4c519ecfbdd498bd" type="targz">http://mvertes.free.fr/download/txt2man-1.5.6.tar.gz</Archive>
    </Source>

    <Package>
        <Name>txt2man</Name>
        <Files>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="man">/usr/share/man</Path>
            <Path fileType="doc">/usr/share/doc</Path>
        </Files>
    </Package>

    <History>
        <Update release="3">
            <Date>2017-03-30</Date>
            <Version>1.5.6</Version>
            <Comment>Rebuild with new toolchain</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-06-09</Date>
            <Version>1.5.6</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2014-05-25</Date>
            <Version>1.5.6</Version>
            <Comment>First release</Comment>
            <Name>Osman Erkan</Name>
            <Email>osman.erkan@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>txt2man</Name>
        <Summary xml:lang="tr">Düz ASCII metinleri man sayfası formatına dönüştürücü</Summary>
        <Description xml:lang="tr">txt2man düz ASCII metinleri man sayfası formatına dönüştürür.</Description>
    </Source>
</PISI>


code:
<PISI>
    <Name>office.postscript</Name>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import shelltools
from pisi.actionsapi import get

def setup():
    # Remove local copies for system libs
    for directory in ["cups/libs", "jpeg", "lcms2", "libpng", "openjpeg", "tiff", "zlib"]:
        shelltools.unlinkDir(directory)

    #pisitools.flags.add("-fno-strict-aliasing")

    autotools.autoreconf("-fi")

    options = "--disable-compile-inits \
               --disable-gtk \
               --enable-dynamic \
               --with-system-libtiff \
               --with-ijs \
               --with-drivers=ALL \
               --with-libpaper \
               --with-jbig2dec \
               --enable-fontconfig \
               --enable-freetype \
               --without-luratech \
               --without-omni \
               --with-x \
               --with-fontpath=/usr/share/fonts:/usr/share/fonts/default/ghostscript:/usr/share/cups/fonts:/usr/share/fonts/TTF:/usr/share/fonts/Type1:/usr/share/poppler/cMap/*"
    options += " --disable-cups --includedir=/usr/include --libdir=/usr/lib32" if get.buildTYPE() == "emul32" else " --enable-cups"

    autotools.configure(options)

    shelltools.cd("ijs/")
    pisitools.dosed("configure.ac", "AM_PROG_CC_STDC", "AC_PROG_CC")
    shelltools.system("./autogen.sh \
                       --prefix=/usr \
                       --mandir=/usr/share/man \
                       --disable-static \
                       --enable-shared")

def build():
    autotools.make("-C ijs")
    autotools.make("so")
    autotools.make("-j1")
    if not get.buildTYPE() == "emul32": autotools.make("cups")

def install():
    autotools.rawInstall("DESTDIR=%s" % get.installDIR())
    autotools.rawInstall("DESTDIR=%s" % get.installDIR(), "soinstall")
    if not get.buildTYPE() == "emul32": autotools.rawInstall("-C ijs DESTDIR=%s" % get.installDIR())

    pisitools.dohtml("doc/*")
    pisitools.dodoc("doc/AUTHORS", "doc/COPYING")


code:
From fee19fa8d4f6f351e5a76f5801884880249d6a45 Mon Sep 17 00:00:00 2001
From: Chris Liddell <chris.liddell@artifex.com>
Date: Wed, 5 Oct 2016 09:55:55 +0100
Subject: [PATCH] Bug 697178: Add a file permissions callback

For the rare occasions when the graphics library directly opens a file
(currently for reading), this allows us to apply any restrictions on
file access normally applied in the interpteter.
---
 base/gsicc_manage.c | 10 ++++++----
 base/gslibctx.c     | 12 +++++++++++-
 base/gslibctx.h     |  7 +++++++
 psi/imain.c         |  2 ++
 psi/int.mak         |  2 +-
 psi/zfile.c         | 19 +++++++++++++++++++
 psi/zfile.h         |  7 +++++++
 7 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/base/gsicc_manage.c b/base/gsicc_manage.c
index 931c2a6..e9c09c3 100644
--- a/base/gsicc_manage.c
+++ b/base/gsicc_manage.c
@@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
     }

     /* First just try it like it is */
-    str = sfopen(pname, "r", mem_gc);
-    if (str != NULL) {
-        *strp = str;
-        return 0;
+    if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+        str = sfopen(pname, "r", mem_gc);
+        if (str != NULL) {
+            *strp = str;
+            return 0;
+        }
     }

     /* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */
diff --git a/base/gslibctx.c b/base/gslibctx.c
index fa4432a..f2c13e3 100644
--- a/base/gslibctx.c
+++ b/base/gslibctx.c
@@ -183,7 +183,7 @@ int gs_lib_ctx_init( gs_memory_t *mem )
         mem->gs_lib_ctx = NULL;
         return -1;
     }
-
+    pio->client_check_file_permission = NULL;
     gp_get_realtime(pio->real_time_0);

     /* Set scanconverter to 1 (default) */
@@ -336,3 +336,13 @@ void errflush(const gs_memory_t *mem)
         fflush(mem->gs_lib_ctx->fstderr);
     /* else nothing to flush */
 }
+
+int
+gs_check_file_permission (gs_memory_t *mem, const char *fname, const int len, const char *permission)
+{
+    int code = 0;
+    if (mem->gs_lib_ctx->client_check_file_permission != NULL) {
+        code = mem->gs_lib_ctx->client_check_file_permission(mem, fname, len, permission);
+    }
+    return code;
+}
diff --git a/base/gslibctx.h b/base/gslibctx.h
index 84ec205..55eb4a6 100644
--- a/base/gslibctx.h
+++ b/base/gslibctx.h
@@ -32,6 +32,9 @@ typedef struct gs_fapi_server_s gs_fapi_server;
 #  define gs_font_dir_DEFINED
 typedef struct gs_font_dir_s gs_font_dir;
 #endif
+
+typedef int (*client_check_file_permission_t) (gs_memory_t *mem, const char *fname, const int len, const char *permission);
+
 typedef struct gs_lib_ctx_s
 {
     gs_memory_t *memory;  /* mem->gs_lib_ctx->memory == mem */
@@ -61,6 +64,7 @@ typedef struct gs_lib_ctx_s
     struct gx_io_device_s **io_device_table;
     int io_device_table_count;
     int io_device_table_size;
+    client_check_file_permission_t client_check_file_permission;
     /* Define the default value of AccurateScreens that affects setscreen
        and setcolorscreen. */
     bool screen_accurate_screens;
@@ -132,6 +136,9 @@ int
 gs_lib_ctx_get_default_device_list(const gs_memory_t *mem, char** dev_list_str,
                         int *list_str_len);

+int
+gs_check_file_permission (gs_memory_t *mem, const char *fname, const int len, const char *permission);
+
 #define IS_LIBCTX_STDOUT(mem, f) (f == mem->gs_lib_ctx->fstdout)
 #define IS_LIBCTX_STDERR(mem, f) (f == mem->gs_lib_ctx->fstderr)

diff --git a/psi/imain.c b/psi/imain.c
index 9a9bb5d..6874128 100644
--- a/psi/imain.c
+++ b/psi/imain.c
@@ -57,6 +57,7 @@
 #include "ivmspace.h"
 #include "idisp.h"              /* for setting display device callback */
 #include "iplugin.h"
+#include "zfile.h"

 #ifdef PACIFY_VALGRIND
 #include "valgrind.h"
@@ -212,6 +213,7 @@ gs_main_init1(gs_main_instance * minst)
                                            "the_gs_name_table");
             if (code < 0)
                 return code;
+            mem->gs_lib_ctx->client_check_file_permission = z_check_file_permissions;
         }
         code = obj_init(&minst->i_ctx_p, &idmem);  /* requires name_init */
         if (code < 0)
diff --git a/psi/int.mak b/psi/int.mak
index 4654afc..bb30d51 100644
--- a/psi/int.mak
+++ b/psi/int.mak
@@ -2024,7 +2024,7 @@ $(PSOBJ)imain.$(OBJ) : $(PSSRC)imain.c $(GH) $(memory__h) $(string__h)\
  $(ialloc_h) $(iconf_h) $(idebug_h) $(idict_h) $(idisp_h) $(iinit_h)\
  $(iname_h) $(interp_h) $(iplugin_h) $(isave_h) $(iscan_h) $(ivmspace_h)\
  $(iinit_h) $(main_h) $(oper_h) $(ostack_h)\
- $(sfilter_h) $(store_h) $(stream_h) $(strimpl_h)\
+ $(sfilter_h) $(store_h) $(stream_h) $(strimpl_h) $(zfile_h)\
  $(INT_MAK) $(MAKEDIRS)
 	$(PSCC) $(PSO_)imain.$(OBJ) $(C_) $(PSSRC)imain.c

diff --git a/psi/zfile.c b/psi/zfile.c
index b6caea2..fd94f67 100644
--- a/psi/zfile.c
+++ b/psi/zfile.c
@@ -197,6 +197,25 @@ check_file_permissions(i_ctx_t *i_ctx_p, const char *fname, int len,
     return check_file_permissions_reduced(i_ctx_p, fname_reduced, rlen, permitgroup);
 }

+/* z_check_file_permissions: see zfile.h for explanation
+ */
+int
+z_check_file_permissions(gs_memory_t *mem, const char *fname, const int len, const char *permission)
+{
+    i_ctx_t *i_ctx_p = get_minst_from_memory(mem)->i_ctx_p;
+    gs_parsed_file_name_t pname;
+    const char *permitgroup = permission[0] == 'r' ? "PermitFileReading" : "PermitFileWriting";
+    int code = gs_parse_file_name(&pname, fname, len, imemory);
+    if (code < 0)
+        return code;
+
+    if (pname.iodev && i_ctx_p->LockFilePermissions && strcmp(pname.iodev->dname, "%pipe%") == 0)
+        return gs_error_invalidfileaccess;
+
+    code = check_file_permissions(i_ctx_p, fname, len, permitgroup);
+    return code;
+}
+
 /* <name_string> <access_string> file <file> */
 int                             /* exported for zsysvm.c */
 zfile(i_ctx_t *i_ctx_p)
diff --git a/psi/zfile.h b/psi/zfile.h
index fdf1373..a9399c7 100644
--- a/psi/zfile.h
+++ b/psi/zfile.h
@@ -22,4 +22,11 @@
 int zopen_file(i_ctx_t *i_ctx_p, const gs_parsed_file_name_t *pfn,
            const char *file_access, stream **ps, gs_memory_t *mem);

+/* z_check_file_permissions: a callback (via mem->gs_lib_ctx->client_check_file_permission)
+ * to allow applying the above permissions checks when opening file(s) from
+ * the graphics library
+ */
+int
+z_check_file_permissions(gs_memory_t *mem, const char *fname,
+                                 const int len, const char *permission);
 #endif
--
2.7.4


code:
From 8abd22010eb4db0fb1b10e430d5f5d83e015ef70 Mon Sep 17 00:00:00 2001
From: Chris Liddell <chris.liddell@artifex.com>
Date: Mon, 3 Oct 2016 01:46:28 +0100
Subject: [PATCH] Bug 697169: Be rigorous with SAFER permissions

Once we've opened our input file from the command line, enforce the SAFER
rules.
---
 psi/zfile.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/psi/zfile.c b/psi/zfile.c
index b6caea2..2c6c958 100644
--- a/psi/zfile.c
+++ b/psi/zfile.c
@@ -1081,6 +1081,9 @@ lib_file_open(gs_file_path_ptr  lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx
     gs_main_instance *minst = get_minst_from_memory(mem);
     int code;

+    if (i_ctx_p && starting_arg_file)
+        i_ctx_p->starting_arg_file = false;
+
     /* when starting arg files (@ files) iodev_default is not yet set */
     if (iodev == 0)
         iodev = (gx_io_device *)gx_io_device_table[0];
--
2.7.4


code:
From 6f749c0c44e7b9e09737b9f29edf29925a34f0cf Mon Sep 17 00:00:00 2001
From: Chris Liddell <chris.liddell@artifex.com>
Date: Wed, 5 Oct 2016 09:59:25 +0100
Subject: [PATCH] Bug 697179: Reference count device icc profile

when copying a device
---
 base/gsdevice.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/base/gsdevice.c b/base/gsdevice.c
index 778106f..aea986a 100644
--- a/base/gsdevice.c
+++ b/base/gsdevice.c
@@ -614,6 +614,7 @@ gx_device_init(gx_device * dev, const gx_device * proto, gs_memory_t * mem,
     dev->memory = mem;
     dev->retained = !internal;
     rc_init(dev, mem, (internal ? 0 : 1));
+    rc_increment(dev->icc_struct);
 }

 void
--
2.7.4


code:
From 875a0095f37626a721c7ff57d606a0f95af03913 Mon Sep 17 00:00:00 2001
From: Ken Sharp <ken.sharp@artifex.com>
Date: Wed, 5 Oct 2016 10:10:58 +0100
Subject: [PATCH] DSC parser - validate parameters

Bug #697190 ".initialize_dsc_parser doesn't validate the parameter is a dict type before using it."

Regardless of any security implications, its simply wrong for a PostScript
operator not to validate its parameter(s).

No differences expected.
---
 psi/zdscpars.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/psi/zdscpars.c b/psi/zdscpars.c
index c05e154..9b4b605 100644
--- a/psi/zdscpars.c
+++ b/psi/zdscpars.c
@@ -150,11 +150,16 @@ zinitialize_dsc_parser(i_ctx_t *i_ctx_p)
     ref local_ref;
     int code;
     os_ptr const op = osp;
-    dict * const pdict = op->value.pdict;
-    gs_memory_t * const mem = (gs_memory_t *)dict_memory(pdict);
-    dsc_data_t * const data =
-        gs_alloc_struct(mem, dsc_data_t, &st_dsc_data_t, "DSC parser init");
+    dict *pdict;
+    gs_memory_t *mem;
+    dsc_data_t *data;

+    check_read_type(*op, t_dictionary);
+
+    pdict = op->value.pdict;
+    mem = (gs_memory_t *)dict_memory(pdict);
+
+    data = gs_alloc_struct(mem, dsc_data_t, &st_dsc_data_t, "DSC parser init");
     if (!data)
         return_error(gs_error_VMerror);
     data->document_level = 0;
--
2.7.4


code:
From f5c7555c30393e64ec1f5ab0dfae5b55b3b3fc78 Mon Sep 17 00:00:00 2001
From: Chris Liddell <chris.liddell@artifex.com>
Date: Sat, 8 Oct 2016 16:10:27 +0100
Subject: [PATCH] Bug 697203: check for sufficient params in .sethalftone5

and param types
---
 psi/zht2.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/psi/zht2.c b/psi/zht2.c
index fb4a264..dfa27a4 100644
--- a/psi/zht2.c
+++ b/psi/zht2.c
@@ -82,14 +82,22 @@ zsethalftone5(i_ctx_t *i_ctx_p)
     gs_memory_t *mem;
     uint edepth = ref_stack_count(&e_stack);
     int npop = 2;
-    int dict_enum = dict_first(op);
+    int dict_enum;
     ref rvalue[2];
     int cname, colorant_number;
     byte * pname;
     uint name_size;
     int halftonetype, type = 0;
     gs_gstate *pgs = igs;
-    int space_index = r_space_index(op - 1);
+    int space_index;
+
+    if (ref_stack_count(&o_stack) < 2)
+        return_error(gs_error_stackunderflow);
+    check_type(*op, t_dictionary);
+    check_type(*(op - 1), t_dictionary);
+
+    dict_enum = dict_first(op);
+    space_index = r_space_index(op - 1);

     mem = (gs_memory_t *) idmemory->spaces_indexed[space_index];

--
2.7.4


code:
From cecf6b592945d247bf932f6a4f50065db4acfba8 Mon Sep 17 00:00:00 2001
From: Robin Watts <robin.watts@artifex.com>
Date: Mon, 12 Dec 2016 17:47:17 +0000
Subject: [PATCH] Squash signed/unsigned warnings in MSVC jbig2 build.

Also rename "new" to "new_dict", because "new" is a bad
variable name.
---
 jbig2dec/jbig2.c             |  4 +--
 jbig2dec/jbig2.h             |  8 +++--
 jbig2dec/jbig2_generic.c     |  2 +-
 jbig2dec/jbig2_halftone.c    | 24 +++++++--------
 jbig2dec/jbig2_huffman.c     | 10 +++---
 jbig2dec/jbig2_huffman.h     |  2 +-
 jbig2dec/jbig2_image.c       | 32 +++++++++----------
 jbig2dec/jbig2_mmr.c         | 66 ++++++++++++++++++++-------------------
 jbig2dec/jbig2_page.c        |  6 ++--
 jbig2dec/jbig2_priv.h        |  4 +--
 jbig2dec/jbig2_segment.c     | 10 +++---
 jbig2dec/jbig2_symbol_dict.c | 73 ++++++++++++++++++++++----------------------
 jbig2dec/jbig2_symbol_dict.h |  6 ++--
 jbig2dec/jbig2_text.c        | 16 +++++-----
 jbig2dec/jbig2_text.h        |  2 +-
 15 files changed, 134 insertions(+), 131 deletions(-)

diff --git a/jbig2dec/jbig2.c b/jbig2dec/jbig2.c
index f729e29..e51380f 100644
--- a/jbig2dec/jbig2.c
+++ b/jbig2dec/jbig2.c
@@ -379,7 +379,7 @@ typedef struct {
 } Jbig2WordStreamBuf;

 static int
-jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, int offset, uint32_t *word)
+jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, size_t offset, uint32_t *word)
 {
     Jbig2WordStreamBuf *z = (Jbig2WordStreamBuf *) self;
     const byte *data = z->data;
@@ -390,7 +390,7 @@ jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, int offset, uint32_t
     else if (offset > z->size)
         return -1;
     else {
-        int i;
+        size_t i;

         result = 0;
         for (i = 0; i < z->size - offset; i++)
diff --git a/jbig2dec/jbig2.h b/jbig2dec/jbig2.h
index d5aa52f..624e0ed 100644
--- a/jbig2dec/jbig2.h
+++ b/jbig2dec/jbig2.h
@@ -56,17 +56,19 @@ typedef struct _Jbig2SymbolDictionary Jbig2SymbolDictionary;
 */

 struct _Jbig2Image {
-    int width, height, stride;
+    uint32_t width;
+    uint32_t height;
+    uint32_t stride;
     uint8_t *data;
     int refcount;
 };

-Jbig2Image *jbig2_image_new(Jbig2Ctx *ctx, int width, int height);
+Jbig2Image *jbig2_image_new(Jbig2Ctx *ctx, uint32_t width, uint32_t height);
 Jbig2Image *jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image);
 void jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image);
 void jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image);
 void jbig2_image_clear(Jbig2Ctx *ctx, Jbig2Image *image, int value);
-Jbig2Image *jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, int width, int height);
+Jbig2Image *jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t height);

 /* errors are returned from the library via a callback. If no callback
    is provided (a NULL argument is passed ot jbig2_ctx_new) a default
diff --git a/jbig2dec/jbig2_generic.c b/jbig2dec/jbig2_generic.c
index 02fdbfb..9656198 100644
--- a/jbig2dec/jbig2_generic.c
+++ b/jbig2dec/jbig2_generic.c
@@ -718,7 +718,7 @@ jbig2_immediate_generic_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte
     byte seg_flags;
     int8_t gbat[8];
     int offset;
-    int gbat_bytes = 0;
+    uint32_t gbat_bytes = 0;
     Jbig2GenericRegionParams params;
     int code = 0;
     Jbig2Image *image = NULL;
diff --git a/jbig2dec/jbig2_halftone.c b/jbig2dec/jbig2_halftone.c
index aeab576..acfbc56 100644
--- a/jbig2dec/jbig2_halftone.c
+++ b/jbig2dec/jbig2_halftone.c
@@ -257,8 +257,8 @@ jbig2_decode_gray_scale_image(Jbig2Ctx *ctx, Jbig2Segment *segment,
 {
     uint8_t **GSVALS = NULL;
     size_t consumed_bytes = 0;
-    int i, j, code, stride;
-    int x, y;
+    uint32_t i, j, stride, x, y;
+    int code;
     Jbig2Image **GSPLANES;
     Jbig2GenericRegionParams rparams;
     Jbig2WordStream *ws = NULL;
@@ -276,9 +276,8 @@ jbig2_decode_gray_scale_image(Jbig2Ctx *ctx, Jbig2Segment *segment,
         if (GSPLANES[i] == NULL) {
             jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate %dx%d image for GSPLANES", GSW, GSH);
             /* free already allocated */
-            for (j = i - 1; j >= 0; --j) {
-                jbig2_image_release(ctx, GSPLANES[j]);
-            }
+            for (j = i; j > 0;)
+                jbig2_image_release(ctx, GSPLANES[--j]);
             jbig2_free(ctx->allocator, GSPLANES);
             return NULL;
         }
@@ -323,9 +322,10 @@ jbig2_decode_gray_scale_image(Jbig2Ctx *ctx, Jbig2Segment *segment,
     }

     /* C.5 step 2. Set j = GSBPP-2 */
-    j = GSBPP - 2;
+    j = GSBPP - 1;
     /* C.5 step 3. decode loop */
-    while (j >= 0) {
+    while (j > 0) {
+        j--;
         /*  C.5 step 3. (a) */
         if (GSMMR) {
             code = jbig2_decode_halftone_mmr(ctx, &rparams, data + consumed_bytes, size - consumed_bytes, GSPLANES[j], &consumed_bytes);
@@ -345,7 +345,6 @@ jbig2_decode_gray_scale_image(Jbig2Ctx *ctx, Jbig2Segment *segment,
             GSPLANES[j]->data[i] ^= GSPLANES[j + 1]->data[i];

         /*  C.5 step 3. (c) */
-        --j;
     }

     /* allocate GSVALS */
@@ -359,9 +358,8 @@ jbig2_decode_gray_scale_image(Jbig2Ctx *ctx, Jbig2Segment *segment,
         if (GSVALS[i] == NULL) {
             jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate GSVALS: %d bytes", GSH * GSW);
             /* free already allocated */
-            for (j = i - 1; j >= 0; --j) {
-                jbig2_free(ctx->allocator, GSVALS[j]);
-            }
+            for (j = i; j > 0;)
+                jbig2_free(ctx->allocator, GSVALS[--j]);
             jbig2_free(ctx->allocator, GSVALS);
             GSVALS = NULL;
             goto cleanup;
@@ -450,7 +448,7 @@ jbig2_decode_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
     uint8_t **GI;
     Jbig2Image *HSKIP = NULL;
     Jbig2PatternDict *HPATS;
-    int i;
+    uint32_t i;
     uint32_t mg, ng;
     int32_t x, y;
     uint8_t gray_val;
@@ -476,7 +474,7 @@ jbig2_decode_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment,

     /* calculate ceil(log2(HNUMPATS)) */
     HBPP = 0;
-    while (HNUMPATS > (1 << ++HBPP));
+    while (HNUMPATS > (1U << ++HBPP));

     /* 6.6.5 point 4. decode gray-scale image as mentioned in annex C */
     GI = jbig2_decode_gray_scale_image(ctx, segment, data, size,
diff --git a/jbig2dec/jbig2_huffman.c b/jbig2dec/jbig2_huffman.c
index 4521b48..f77981b 100644
--- a/jbig2dec/jbig2_huffman.c
+++ b/jbig2dec/jbig2_huffman.c
@@ -47,16 +47,16 @@ struct _Jbig2HuffmanState {
        is (offset + 4) * 8. */
     uint32_t this_word;
     uint32_t next_word;
-    int offset_bits;
-    int offset;
-    int offset_limit;
+    uint32_t offset_bits;
+    uint32_t offset;
+    uint32_t offset_limit;

     Jbig2WordStream *ws;
     Jbig2Ctx *ctx;
 };

 static uint32_t
-huff_get_next_word(Jbig2HuffmanState *hs, int offset)
+huff_get_next_word(Jbig2HuffmanState *hs, uint32_t offset)
 {
     uint32_t word = 0;
     Jbig2WordStream *ws = hs->ws;
@@ -213,7 +213,7 @@ jbig2_huffman_advance(Jbig2HuffmanState *hs, int offset)
 /* return the offset of the huffman decode pointer (in bytes)
  * from the beginning of the WordStream
  */
-int
+uint32_t
 jbig2_huffman_offset(Jbig2HuffmanState *hs)
 {
     return hs->offset + (hs->offset_bits >> 3);
diff --git a/jbig2dec/jbig2_huffman.h b/jbig2dec/jbig2_huffman.h
index 5d1e6e0..cfda9e0 100644
--- a/jbig2dec/jbig2_huffman.h
+++ b/jbig2dec/jbig2_huffman.h
@@ -64,7 +64,7 @@ void jbig2_huffman_skip(Jbig2HuffmanState *hs);

 void jbig2_huffman_advance(Jbig2HuffmanState *hs, int offset);

-int jbig2_huffman_offset(Jbig2HuffmanState *hs);
+uint32_t jbig2_huffman_offset(Jbig2HuffmanState *hs);

 int32_t jbig2_huffman_get(Jbig2HuffmanState *hs, const Jbig2HuffmanTable *table, bool *oob);

diff --git a/jbig2dec/jbig2_image.c b/jbig2dec/jbig2_image.c
index 1ae614e..94e5a4c 100644
--- a/jbig2dec/jbig2_image.c
+++ b/jbig2dec/jbig2_image.c
@@ -32,10 +32,10 @@

 /* allocate a Jbig2Image structure and its associated bitmap */
 Jbig2Image *
-jbig2_image_new(Jbig2Ctx *ctx, int width, int height)
+jbig2_image_new(Jbig2Ctx *ctx, uint32_t width, uint32_t height)
 {
     Jbig2Image *image;
-    int stride;
+    uint32_t stride;
     int64_t check;

     image = jbig2_new(ctx, Jbig2Image, 1);
@@ -99,7 +99,7 @@ jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image)

 /* resize a Jbig2Image */
 Jbig2Image *
-jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, int width, int height)
+jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t height)
 {
     if (width == image->width) {
         /* check for integer multiplication overflow */
@@ -133,11 +133,11 @@ jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, int width, int height)
 static int
 jbig2_image_compose_unopt(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y, Jbig2ComposeOp op)
 {
-    int i, j;
-    int sw = src->width;
-    int sh = src->height;
-    int sx = 0;
-    int sy = 0;
+    uint32_t i, j;
+    uint32_t sw = src->width;
+    uint32_t sh = src->height;
+    uint32_t sx = 0;
+    uint32_t sy = 0;

     /* clip to the dst image boundaries */
     if (x < 0) {
@@ -200,10 +200,10 @@ jbig2_image_compose_unopt(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x
 int
 jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y, Jbig2ComposeOp op)
 {
-    int i, j;
-    int w, h;
-    int leftbyte, rightbyte;
-    int shift;
+    uint32_t i, j;
+    uint32_t w, h;
+    uint32_t leftbyte, rightbyte;
+    uint32_t shift;
     uint8_t *s, *ss;
     uint8_t *d, *dd;
     uint8_t mask, rightmask;
@@ -226,8 +226,8 @@ jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int
         h += y;
         y = 0;
     }
-    w = (x + w < dst->width) ? w : dst->width - x;
-    h = (y + h < dst->height) ? h : dst->height - y;
+    w = ((uint32_t)x + w < dst->width) ? w : ((dst->width >= (uint32_t)x) ? dst->width - (uint32_t)x : 0);
+    h = ((uint32_t)y + h < dst->height) ? h : ((dst->height >= (uint32_t)y) ? dst->height - (uint32_t)y : 0);
 #ifdef JBIG2_DEBUG
     jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "compositing %dx%d at (%d, %d) after clipping\n", w, h, x, y);
 #endif
@@ -249,8 +249,8 @@ jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int
     }
 #endif

-    leftbyte = x >> 3;
-    rightbyte = (x + w - 1) >> 3;
+    leftbyte = (uint32_t)x >> 3;
+    rightbyte = ((uint32_t)x + w - 1) >> 3;
     shift = x & 7;

     /* general OR case */
diff --git a/jbig2dec/jbig2_mmr.c b/jbig2dec/jbig2_mmr.c
index d4cd3a2..390e27c 100644
--- a/jbig2dec/jbig2_mmr.c
+++ b/jbig2dec/jbig2_mmr.c
@@ -38,19 +38,21 @@
 #include "jbig2_mmr.h"

 typedef struct {
-    int width;
-    int height;
+    uint32_t width;
+    uint32_t height;
     const byte *data;
     size_t size;
-    int data_index;
-    int bit_index;
+    uint32_t data_index;
+    uint32_t bit_index;
     uint32_t word;
 } Jbig2MmrCtx;

+#define MINUS1 ((uint32_t)-1)
+
 static void
 jbig2_decode_mmr_init(Jbig2MmrCtx *mmr, int width, int height, const byte *data, size_t size)
 {
-    int i;
+    size_t i;
     uint32_t word = 0;

     mmr->width = width;
@@ -732,14 +734,14 @@ const mmr_table_node jbig2_mmr_black_decode[] = {
 #define getbit(buf, x) ( ( buf[x >> 3] >> ( 7 - (x & 7) ) ) & 1 )

 static int
-jbig2_find_changing_element(const byte *line, int x, int w)
+jbig2_find_changing_element(const byte *line, uint32_t x, uint32_t w)
 {
     int a, b;

     if (line == 0)
-        return w;
+        return (int)w;

-    if (x == -1) {
+    if (x == MINUS1) {
         a = 0;
         x = 0;
     } else {
@@ -758,7 +760,7 @@ jbig2_find_changing_element(const byte *line, int x, int w)
 }

 static int
-jbig2_find_changing_element_of_color(const byte *line, int x, int w, int color)
+jbig2_find_changing_element_of_color(const byte *line, uint32_t x, uint32_t w, int color)
 {
     if (line == 0)
         return w;
@@ -772,9 +774,9 @@ static const byte lm[8] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01 };
 static const byte rm[8] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };

 static void
-jbig2_set_bits(byte *line, int x0, int x1)
+jbig2_set_bits(byte *line, uint32_t x0, uint32_t x1)
 {
-    int a0, a1, b0, b1, a;
+    uint32_t a0, a1, b0, b1, a;

     a0 = x0 >> 3;
     a1 = x1 >> 3;
@@ -831,8 +833,8 @@ jbig2_decode_get_run(Jbig2MmrCtx *mmr, const mmr_table_node *table, int initial_
 static int
 jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
 {
-    int a0 = -1;
-    int a1, a2, b1, b2;
+    uint32_t a0 = MINUS1;
+    uint32_t a1, a2, b1, b2;
     int c = 0;                  /* 0 is white, black is 1 */

     while (1) {
@@ -840,7 +842,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)

         /* printf ("%08x\n", word); */

-        if (a0 >= mmr->width)
+        if (a0 != MINUS1 && a0 >= mmr->width)
             break;

         if ((word >> (32 - 3)) == 1) {
@@ -848,7 +850,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)

             jbig2_decode_mmr_consume(mmr, 3);

-            if (a0 == -1)
+            if (a0 == MINUS1)
                 a0 = 0;

             if (c == 0) {
@@ -860,7 +862,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
                     a1 = mmr->width;
                 if (a2 > mmr->width)
                     a2 = mmr->width;
-                if (a2 < a1 || a1 < 0)
+                if (a1 == MINUS1 || a2 < a1)
                     return -1;
                 jbig2_set_bits(dst, a1, a2);
                 a0 = a2;
@@ -874,7 +876,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
                     a1 = mmr->width;
                 if (a2 > mmr->width)
                     a2 = mmr->width;
-                if (a1 < a0 || a0 < 0)
+                if (a0 == MINUS1 || a1 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, a1);
                 a0 = a2;
@@ -888,7 +890,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
             b2 = jbig2_find_changing_element(ref, b1, mmr->width);
             if (c) {
-                if (b2 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b2 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b2);
             }
@@ -900,7 +902,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
             jbig2_decode_mmr_consume(mmr, 1);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
             if (c) {
-                if (b1 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1);
             }
@@ -915,7 +917,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
             if (b1 + 1 > mmr->width)
                 break;
             if (c) {
-                if (b1 + 1 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 + 1 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 + 1);
             }
@@ -930,7 +932,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
             if (b1 + 2 > mmr->width)
                 break;
             if (c) {
-                if (b1 + 2 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 + 2 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 + 2);
             }
@@ -942,10 +944,10 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
             /* printf ("VR(3)\n"); */
             jbig2_decode_mmr_consume(mmr, 7);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 + 3 > mmr->width)
+            if (b1 + 3 > (int)mmr->width)
                 break;
             if (c) {
-                if (b1 + 3 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 + 3 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 + 3);
             }
@@ -957,10 +959,10 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
             /* printf ("VL(1)\n"); */
             jbig2_decode_mmr_consume(mmr, 3);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 - 1 < 0)
+            if (b1 < 1)
                 break;
             if (c) {
-                if (b1 - 1 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 - 1 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 - 1);
             }
@@ -972,7 +974,7 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
             /* printf ("VL(2)\n"); */
             jbig2_decode_mmr_consume(mmr, 6);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 - 2 < 0)
+            if (b1 < 2)
                 break;
             if (c) {
                 if (b1 - 2 < a0 || a0 < 0)
@@ -987,10 +989,10 @@ jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
             /* printf ("VL(3)\n"); */
             jbig2_decode_mmr_consume(mmr, 7);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 - 3 < 0)
+            if (b1 < 3)
                 break;
             if (c) {
-                if (b1 - 3 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 - 3 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 - 3);
             }
@@ -1009,10 +1011,10 @@ int
 jbig2_decode_generic_mmr(Jbig2Ctx *ctx, Jbig2Segment *segment, const Jbig2GenericRegionParams *params, const byte *data, size_t size, Jbig2Image *image)
 {
     Jbig2MmrCtx mmr;
-    const int rowstride = image->stride;
+    const uint32_t rowstride = image->stride;
     byte *dst = image->data;
     byte *ref = NULL;
-    int y;
+    uint32_t y;
     int code = 0;

     jbig2_decode_mmr_init(&mmr, image->width, image->height, data, size);
@@ -1047,10 +1049,10 @@ int
 jbig2_decode_halftone_mmr(Jbig2Ctx *ctx, const Jbig2GenericRegionParams *params, const byte *data, size_t size, Jbig2Image *image, size_t *consumed_bytes)
 {
     Jbig2MmrCtx mmr;
-    const int rowstride = image->stride;
+    const uint32_t rowstride = image->stride;
     byte *dst = image->data;
     byte *ref = NULL;
-    int y;
+    uint32_t y;
     int code = 0;
     const uint32_t EOFB = 0x001001;

diff --git a/jbig2dec/jbig2_page.c b/jbig2dec/jbig2_page.c
index 110ff7c..1ed1c8a 100644
--- a/jbig2dec/jbig2_page.c
+++ b/jbig2dec/jbig2_page.c
@@ -155,9 +155,9 @@ int
 jbig2_end_of_stripe(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data)
 {
     Jbig2Page page = ctx->pages[ctx->current_page];
-    int end_row;
+    uint32_t end_row;

-    end_row = jbig2_get_int32(segment_data);
+    end_row = jbig2_get_uint32(segment_data);
     if (end_row < page.end_row) {
         jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
                     "end of stripe segment with non-positive end row advance" " (new end row %d vs current end row %d)", end_row, page.end_row);
@@ -248,7 +248,7 @@ jbig2_page_add_result(Jbig2Ctx *ctx, Jbig2Page *page, Jbig2Image *image, int x,

     /* grow the page to accomodate a new stripe if necessary */
     if (page->striped) {
-        int new_height = y + image->height + page->end_row;
+        uint32_t new_height = y + image->height + page->end_row;

         if (page->image->height < new_height) {
             jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "growing page buffer to %d rows " "to accomodate new stripe", new_height);
diff --git a/jbig2dec/jbig2_priv.h b/jbig2dec/jbig2_priv.h
index 42ba496..3d44b42 100644
--- a/jbig2dec/jbig2_priv.h
+++ b/jbig2dec/jbig2_priv.h
@@ -132,7 +132,7 @@ struct _Jbig2Page {
     uint32_t x_resolution, y_resolution;        /* in pixels per meter */
     uint16_t stripe_size;
     bool striped;
-    int end_row;
+    uint32_t end_row;
     uint8_t flags;
     Jbig2Image *image;
 };
@@ -182,7 +182,7 @@ int jbig2_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segm
 typedef struct _Jbig2WordStream Jbig2WordStream;

 struct _Jbig2WordStream {
-    int (*get_next_word)(Jbig2WordStream *self, int offset, uint32_t *word);
+    int (*get_next_word)(Jbig2WordStream *self, size_t offset, uint32_t *word);
 };

 Jbig2WordStream *jbig2_word_stream_buf_new(Jbig2Ctx *ctx, const byte *data, size_t size);
diff --git a/jbig2dec/jbig2_segment.c b/jbig2dec/jbig2_segment.c
index 2e0db67..5b63706 100644
--- a/jbig2dec/jbig2_segment.c
+++ b/jbig2dec/jbig2_segment.c
@@ -39,10 +39,10 @@ jbig2_parse_segment_header(Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size, size_t
     uint8_t rtscarf;
     uint32_t rtscarf_long;
     uint32_t *referred_to_segments;
-    int referred_to_segment_count;
-    int referred_to_segment_size;
-    int pa_size;
-    int offset;
+    uint32_t referred_to_segment_count;
+    uint32_t referred_to_segment_size;
+    uint32_t pa_size;
+    uint32_t offset;

     /* minimum possible size of a jbig2 segment header */
     if (buf_size < 11)
@@ -83,7 +83,7 @@ jbig2_parse_segment_header(Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size, size_t

     /* 7.2.5 */
     if (referred_to_segment_count) {
-        int i;
+        uint32_t i;

         referred_to_segments = jbig2_new(ctx, uint32_t, referred_to_segment_count * referred_to_segment_size);
         if (referred_to_segments == NULL) {
diff --git a/jbig2dec/jbig2_symbol_dict.c b/jbig2dec/jbig2_symbol_dict.c
index 2c71a4c..11a2252 100644
--- a/jbig2dec/jbig2_symbol_dict.c
+++ b/jbig2dec/jbig2_symbol_dict.c
@@ -88,40 +88,40 @@ jbig2_dump_symbol_dict(Jbig2Ctx *ctx, Jbig2Segment *segment)

 /* return a new empty symbol dict */
 Jbig2SymbolDict *
-jbig2_sd_new(Jbig2Ctx *ctx, int n_symbols)
+jbig2_sd_new(Jbig2Ctx *ctx, uint32_t n_symbols)
 {
-    Jbig2SymbolDict *new = NULL;
+    Jbig2SymbolDict *new_dict = NULL;

     if (n_symbols < 0) {
         jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "Negative number of symbols in symbol dict: %d", n_symbols);
         return NULL;
     }

-    new = jbig2_new(ctx, Jbig2SymbolDict, 1);
-    if (new != NULL) {
-        new->glyphs = jbig2_new(ctx, Jbig2Image *, n_symbols);
-        new->n_symbols = n_symbols;
+    new_dict = jbig2_new(ctx, Jbig2SymbolDict, 1);
+    if (new_dict != NULL) {
+        new_dict->glyphs = jbig2_new(ctx, Jbig2Image *, n_symbols);
+        new_dict->n_symbols = n_symbols;
     } else {
         jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to allocate new empty symbol dict");
         return NULL;
     }

-    if (new->glyphs != NULL) {
-        memset(new->glyphs, 0, n_symbols * sizeof(Jbig2Image *));
+    if (new_dict->glyphs != NULL) {
+        memset(new_dict->glyphs, 0, n_symbols * sizeof(Jbig2Image *));
     } else {
         jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to allocate glyphs for new empty symbol dict");
-        jbig2_free(ctx->allocator, new);
+        jbig2_free(ctx->allocator, new_dict);
         return NULL;
     }

-    return new;
+    return new_dict;
 }

 /* release the memory associated with a symbol dict */
 void
 jbig2_sd_release(Jbig2Ctx *ctx, Jbig2SymbolDict *dict)
 {
-    int i;
+    uint32_t i;

     if (dict == NULL)
         return;
@@ -142,12 +142,12 @@ jbig2_sd_glyph(Jbig2SymbolDict *dict, unsigned int id)
 }

 /* count the number of dictionary segments referred to by the given segment */
-int
+uint32_t
 jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
 {
     int index;
     Jbig2Segment *rsegment;
-    int n_dicts = 0;
+    uint32_t n_dicts = 0;

     for (index = 0; index < segment->referred_to_segment_count; index++) {
         rsegment = jbig2_find_segment(ctx, segment->referred_to_segments[index]);
@@ -166,8 +166,8 @@ jbig2_sd_list_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
     int index;
     Jbig2Segment *rsegment;
     Jbig2SymbolDict **dicts;
-    int n_dicts = jbig2_sd_count_referred(ctx, segment);
-    int dindex = 0;
+    uint32_t n_dicts = jbig2_sd_count_referred(ctx, segment);
+    uint32_t dindex = 0;

     dicts = jbig2_new(ctx, Jbig2SymbolDict *, n_dicts);
     if (dicts == NULL) {
@@ -195,10 +195,10 @@ jbig2_sd_list_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
 /* generate a new symbol dictionary by concatenating a list of
    existing dictionaries */
 Jbig2SymbolDict *
-jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts, Jbig2SymbolDict **dicts)
+jbig2_sd_cat(Jbig2Ctx *ctx, uint32_t n_dicts, Jbig2SymbolDict **dicts)
 {
-    int i, j, k, symbols;
-    Jbig2SymbolDict *new = NULL;
+    uint32_t i, j, k, symbols;
+    Jbig2SymbolDict *new_dict = NULL;

     /* count the imported symbols and allocate a new array */
     symbols = 0;
@@ -206,17 +206,17 @@ jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts, Jbig2SymbolDict **dicts)
         symbols += dicts[i]->n_symbols;

     /* fill a new array with cloned glyph pointers */
-    new = jbig2_sd_new(ctx, symbols);
-    if (new != NULL) {
+    new_dict = jbig2_sd_new(ctx, symbols);
+    if (new_dict != NULL) {
         k = 0;
         for (i = 0; i < n_dicts; i++)
             for (j = 0; j < dicts[i]->n_symbols; j++)
-                new->glyphs[k++] = jbig2_image_clone(ctx, dicts[i]->glyphs[j]);
+                new_dict->glyphs[k++] = jbig2_image_clone(ctx, dicts[i]->glyphs[j]);
     } else {
         jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to allocate new symbol dictionary");
     }

-    return new;
+    return new_dict;
 }

 /* Decoding routines */
@@ -431,7 +431,7 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,

                     if (REFAGGNINST > 1) {
                         Jbig2Image *image;
-                        int i;
+                        uint32_t i;

                         if (tparams == NULL) {
                             /* First time through, we need to initialise the */
@@ -512,7 +512,7 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
                         uint32_t ID;
                         int32_t RDX, RDY;
                         int BMSIZE = 0;
-                        int ninsyms = params->SDNUMINSYMS;
+                        uint32_t ninsyms = params->SDNUMINSYMS;
                         int code1 = 0;
                         int code2 = 0;
                         int code3 = 0;
@@ -609,8 +609,9 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
         if (params->SDHUFF && !params->SDREFAGG) {
             /* 6.5.9 */
             Jbig2Image *image;
-            int BMSIZE = jbig2_huffman_get(hs, params->SDHUFFBMSIZE, &code);
-            int j, x;
+            uint32_t BMSIZE = jbig2_huffman_get(hs, params->SDHUFFBMSIZE, &code);
+            uint32_t j;
+            int x;

             if (code || (BMSIZE < 0)) {
                 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "error decoding size of collective bitmap!");
@@ -700,22 +701,22 @@ jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
         jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate symbols exported from symbols dictionary");
         goto cleanup4;
     } else {
-        int i = 0;
-        int j = 0;
-        int k;
+        uint32_t i = 0;
+        uint32_t j = 0;
+        uint32_t k;
         int exflag = 0;
-        int64_t limit = params->SDNUMINSYMS + params->SDNUMNEWSYMS;
-        int32_t exrunlength;
+        uint32_t limit = params->SDNUMINSYMS + params->SDNUMNEWSYMS;
+        uint32_t exrunlength;
         int zerolength = 0;

         while (i < limit) {
             if (params->SDHUFF)
                 exrunlength = jbig2_huffman_get(hs, SBHUFFRSIZE, &code);
             else
-                code = jbig2_arith_int_decode(IAEX, as, &exrunlength);
+                code = jbig2_arith_int_decode(IAEX, as, (int32_t *)&exrunlength);
             /* prevent infinite loop */
             zerolength = exrunlength > 0 ? 0 : zerolength + 1;
-            if (code || (exrunlength > limit - i) || (exrunlength < 0) || (zerolength > 4) || (exflag && (exrunlength > params->SDNUMEXSYMS - j))) {
+            if (code || (exrunlength > limit - i) || (exrunlength < 0) || (zerolength > 4) || (exflag && (exrunlength + j > params->SDNUMEXSYMS))) {
                 if (code)
                     jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode exrunlength for exported symbols");
                 else if (exrunlength <= 0)
@@ -797,8 +798,8 @@ jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segmen
 {
     Jbig2SymbolDictParams params;
     uint16_t flags;
-    int sdat_bytes;
-    int offset;
+    uint32_t sdat_bytes;
+    uint32_t offset;
     Jbig2ArithCx *GB_stats = NULL;
     Jbig2ArithCx *GR_stats = NULL;
     int table_index = 0;
@@ -951,7 +952,7 @@ jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segmen

     /* 7.4.2.2 (2) */
     {
-        int n_dicts = jbig2_sd_count_referred(ctx, segment);
+        uint32_t n_dicts = jbig2_sd_count_referred(ctx, segment);
         Jbig2SymbolDict **dicts = NULL;

         if (n_dicts > 0) {
diff --git a/jbig2dec/jbig2_symbol_dict.h b/jbig2dec/jbig2_symbol_dict.h
index d56d62d..30211d4 100644
--- a/jbig2dec/jbig2_symbol_dict.h
+++ b/jbig2dec/jbig2_symbol_dict.h
@@ -32,18 +32,18 @@ int jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *se
 Jbig2Image *jbig2_sd_glyph(Jbig2SymbolDict *dict, unsigned int id);

 /* return a new empty symbol dict */
-Jbig2SymbolDict *jbig2_sd_new(Jbig2Ctx *ctx, int n_symbols);
+Jbig2SymbolDict *jbig2_sd_new(Jbig2Ctx *ctx, uint32_t n_symbols);

 /* release the memory associated with a symbol dict */
 void jbig2_sd_release(Jbig2Ctx *ctx, Jbig2SymbolDict *dict);

 /* generate a new symbol dictionary by concatenating a list of
    existing dictionaries */
-Jbig2SymbolDict *jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts, Jbig2SymbolDict **dicts);
+Jbig2SymbolDict *jbig2_sd_cat(Jbig2Ctx *ctx, uint32_t n_dicts, Jbig2SymbolDict **dicts);

 /* count the number of dictionary segments referred
    to by the given segment */
-int jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment);
+uint32_t jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment);

 /* return an array of pointers to symbol dictionaries referred
    to by a segment */
diff --git a/jbig2dec/jbig2_text.c b/jbig2dec/jbig2_text.c
index 5c99640..e77460f 100644
--- a/jbig2dec/jbig2_text.c
+++ b/jbig2dec/jbig2_text.c
@@ -55,7 +55,7 @@
 int
 jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
                          const Jbig2TextRegionParams *params,
-                         const Jbig2SymbolDict *const *dicts, const int n_dicts,
+                         const Jbig2SymbolDict *const *dicts, const uint32_t n_dicts,
                          Jbig2Image *image, const byte *data, const size_t size, Jbig2ArithCx *GR_stats, Jbig2ArithState *as, Jbig2WordStream *ws)
 {
     /* relevent bits of 6.4.4 */
@@ -476,19 +476,19 @@ cleanup2:
 int
 jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data)
 {
-    int offset = 0;
+    uint32_t offset = 0;
     Jbig2RegionSegmentInfo region_info;
     Jbig2TextRegionParams params;
     Jbig2Image *image = NULL;
     Jbig2SymbolDict **dicts = NULL;
-    int n_dicts = 0;
+    uint32_t n_dicts = 0;
     uint16_t flags = 0;
     uint16_t huffman_flags = 0;
     Jbig2ArithCx *GR_stats = NULL;
     int code = 0;
     Jbig2WordStream *ws = NULL;
     Jbig2ArithState *as = NULL;
-    int table_index = 0;
+    uint32_t table_index = 0;
     const Jbig2HuffmanParams *huffman_params = NULL;

     /* 7.4.1 */
@@ -779,7 +779,7 @@ jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data
         code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "unable to retrive symbol dictionaries! previous parsing error?");
         goto cleanup1;
     } else {
-        int index;
+        uint32_t index;

         if (dicts[0] == NULL) {
             code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to find first referenced symbol dictionary!");
@@ -823,8 +823,8 @@ jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data
     }

     if (!params.SBHUFF) {
-        int SBSYMCODELEN, index;
-        int SBNUMSYMS = 0;
+        uint32_t SBSYMCODELEN, index;
+        uint32_t SBNUMSYMS = 0;

         for (index = 0; index < n_dicts; index++) {
             SBNUMSYMS += dicts[index]->n_symbols;
@@ -840,7 +840,7 @@ jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data
         }

         /* Table 31 */
-        for (SBSYMCODELEN = 0; (1 << SBSYMCODELEN) < SBNUMSYMS; SBSYMCODELEN++) {
+        for (SBSYMCODELEN = 0; (1U << SBSYMCODELEN) < SBNUMSYMS; SBSYMCODELEN++) {
         }
         params.IAID = jbig2_arith_iaid_ctx_new(ctx, SBSYMCODELEN);
         params.IARI = jbig2_arith_int_ctx_new(ctx);
diff --git a/jbig2dec/jbig2_text.h b/jbig2dec/jbig2_text.h
index aec2732..51d242e 100644
--- a/jbig2dec/jbig2_text.h
+++ b/jbig2dec/jbig2_text.h
@@ -70,5 +70,5 @@ typedef struct {
 int
 jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
                          const Jbig2TextRegionParams *params,
-                         const Jbig2SymbolDict *const *dicts, const int n_dicts,
+                         const Jbig2SymbolDict *const *dicts, const uint32_t n_dicts,
                          Jbig2Image *image, const byte *data, const size_t size, Jbig2ArithCx *GR_stats, Jbig2ArithState *as, Jbig2WordStream *ws);
--
2.9.3


code:
From 99cf218dbd5f6fbdbda2ce6872eb9ab7f475c353 Mon Sep 17 00:00:00 2001
From: Chris Liddell <chris.liddell@artifex.com>
Date: Tue, 27 Sep 2016 11:22:18 +0100
Subject: [PATCH 1/2] Add pre-processor define for shared OpenJPEG

---
 Makefile.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.in b/Makefile.in
index 25875ad..2ca2a80 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -290,7 +290,7 @@ JBIG2_CFLAGS=@JBIG2_AUTOCONF_CFLAGS@
 JPX_LIB=@JPX_DECODER@
 SHARE_JPX=@SHARE_JPX@
 JPXSRCDIR=@JPXDIR@
-JPX_CFLAGS=@JPX_AUTOCONF_CFLAGS@ @JPX_SSE_CFLAGS@
+JPX_CFLAGS=-DSHARE_JPX=$(SHARE_JPX) @JPX_AUTOCONF_CFLAGS@ @JPX_SSE_CFLAGS@

 # uncomment the following three lines and one of the last two to
 # compile in the Luratech lwf_jp2 codec
--
2.7.4

From 4f19ab99cac2d8a7d21aea34d8aea0727fad52d3 Mon Sep 17 00:00:00 2001
From: Didier Raboud <odyx@debian.org>
Date: Thu, 6 Oct 2016 17:08:41 +0200
Subject: [PATCH 2/2] Don't pass -DOPJ_STATIC when compiling the OpenJPEG code.

  It makes the symbols hidden when including
  /usr/include/openjpeg-2.1/openjpeg.h.
  Fixes a FTBFS against libopenjp2-7 (>= 2.1.1).

  Debian bug: https://bugs.debian.org/832873
---
 base/lib.mak | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/base/lib.mak b/base/lib.mak
index 173e2c6..cffdc9d 100644
--- a/base/lib.mak
+++ b/base/lib.mak
@@ -1849,7 +1849,7 @@ $(GLOBJ)sjpx_openjpeg.$(OBJ) : $(GLSRC)sjpx_openjpeg.c $(AK) \
  $(memory__h) $(gserror_h) $(gserrors_h) \
  $(gdebug_h) $(strimpl_h) $(sjpx_openjpeg_h) $(LIB_MAK) $(MAKEDIRS)
 	$(GLJPXOPJCC) $(GLO_)sjpx_openjpeg.$(OBJ) \
-		$(C_) -DOPJ_STATIC $(GLSRC)sjpx_openjpeg.c
+		$(C_) $(GLSRC)sjpx_openjpeg.c

 # ---------------- Pixel-difference filters ---------------- #
 # The Predictor facility of the LZW and Flate filters uses these.
--
2.7.4


code:
From 329e0a6d187cc5b5698689d76636ed3214d7efa7 Mon Sep 17 00:00:00 2001
From: Chris Liddell <chris.liddell@artifex.com>
Date: Thu, 3 Nov 2016 13:09:27 +0000
Subject: [PATCH] Bug 697286: handle GlyphDirectory as an array

For high level devices that need to copy CIDFonts, we need to establish the
highest CID in a given CIDFont. If the font has a GlyphDirectory dictionary
the only way to do so is to iterate through the keys to find the highest.

The code handling this ignored that the GlyphDirectory could be an array,
which confused the dictionary content iterator, and caused a segfault.

In the case of an array, set the high CID to the highest index available in the
array.
---
 psi/zfcid.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/psi/zfcid.c b/psi/zfcid.c
index ce583af..3098a22 100644
--- a/psi/zfcid.c
+++ b/psi/zfcid.c
@@ -76,15 +76,19 @@ cid_font_data_param(os_ptr op, gs_font_cid_data *pdata, ref *pGlyphDirectory)
          * the number of CIDs in the font. We need to know the maximum CID
          * when copying fonts, so calculate and store it now.
          */
-        index = dict_first(pgdir);
-        while (index >= 0) {
-            index = dict_next(pgdir, index, (ref *)&element);
-            if (index >= 0) {
-                if (element[0].value.intval > pdata->MaxCID)
-                    pdata->MaxCID = element[0].value.intval;
+        if (r_has_type(pgdir, t_dictionary)) {
+            index = dict_first(pgdir);
+            while (index >= 0) {
+                index = dict_next(pgdir, index, (ref *)&element);
+                if (index >= 0) {
+                    if (element[0].value.intval > pdata->MaxCID)
+                        pdata->MaxCID = element[0].value.intval;
+                }
             }
         }
-
+        else {
+            pdata->MaxCID = r_size(pgdir) - 1;
+        }
         return code;
     } else {
         return_error(gs_error_typecheck);
--
2.7.4