···11+From cd8b5c97b27a5c1dc83046498b6ca49ad20aa9b6 Mon Sep 17 00:00:00 2001
22+From: Leon Bottou <leon@bottou.org>
33+Date: Tue, 11 May 2021 14:44:09 -0400
44+Subject: [PATCH] Reviewed Fedora patches and adopted some of them (or variants
55+ thereof)
66+77+ - Patch0: djvulibre-3.5.22-cdefs.patch (forward ported)
88+Does not make imuch sense. GSmartPointer.h already includes "stddef.h"
99+ - Patch6: djvulibre-3.5.27-export-file.patch (forward ported)
1010+Incorrect: inkscape command is --export-png, not --export-filename.
1111+ - Patch8: djvulibre-3.5.27-check-image-size.patch (forward ported)
1212+Correct: adopted a variant of this
1313+ - Patch9: djvulibre-3.5.27-integer-overflow.patch (forward ported)
1414+Correct: adopted a variant of this
1515+ - Patch10: djvulibre-3.5.27-check-input-pool.patch (forward ported)
1616+Adopted: input validation never hurts
1717+ - Patch11: djvulibre-3.5.27-djvuport-stack-overflow.patch (forward ported)
1818+Dubious: Instead I changed djvufile to prevent a file from including itself
1919+which is the only way I can imagine to create an file creation loop.
2020+ - Patch12: djvulibre-3.5.27-unsigned-short-overflow.patch (forward ported)
2121+Adopted: but without including limits.h
2222+---
2323+ libdjvu/DataPool.cpp | 3 ++-
2424+ libdjvu/DjVuFile.cpp | 2 ++
2525+ libdjvu/GBitmap.cpp | 2 ++
2626+ libdjvu/IW44Image.cpp | 4 ++++
2727+ tools/ddjvu.cpp | 7 +++++--
2828+ 5 files changed, 15 insertions(+), 3 deletions(-)
2929+3030+diff --git a/libdjvu/DataPool.cpp b/libdjvu/DataPool.cpp
3131+index 5fcbedf..b58fc45 100644
3232+--- a/libdjvu/DataPool.cpp
3333++++ b/libdjvu/DataPool.cpp
3434+@@ -790,7 +790,8 @@ DataPool::create(const GP<DataPool> & pool, int start, int length)
3535+ {
3636+ DEBUG_MSG("DataPool::DataPool: pool=" << (void *)((DataPool *)pool) << " start=" << start << " length= " << length << "\n");
3737+ DEBUG_MAKE_INDENT(3);
3838+-
3939++ if (!pool)
4040++ G_THROW( ERR_MSG("DataPool.zero_DataPool") );
4141+ DataPool *xpool=new DataPool();
4242+ GP<DataPool> retval=xpool;
4343+ xpool->init();
4444+diff --git a/libdjvu/DjVuFile.cpp b/libdjvu/DjVuFile.cpp
4545+index 143346b..2587491 100644
4646+--- a/libdjvu/DjVuFile.cpp
4747++++ b/libdjvu/DjVuFile.cpp
4848+@@ -576,6 +576,8 @@ DjVuFile::process_incl_chunk(ByteStream & str, int file_num)
4949+ GURL incl_url=pcaster->id_to_url(this, incl_str);
5050+ if (incl_url.is_empty()) // Fallback. Should never be used.
5151+ incl_url=GURL::UTF8(incl_str,url.base());
5252++ if (incl_url == url) // Infinite loop avoidance
5353++ G_THROW( ERR_MSG("DjVuFile.malformed") );
5454+5555+ // Now see if there is already a file with this *name* created
5656+ {
5757+diff --git a/libdjvu/GBitmap.cpp b/libdjvu/GBitmap.cpp
5858+index c2fdbe4..8ad64b2 100644
5959+--- a/libdjvu/GBitmap.cpp
6060++++ b/libdjvu/GBitmap.cpp
6161+@@ -1284,6 +1284,8 @@ GBitmap::decode(unsigned char *runs)
6262+ // initialize pixel array
6363+ if (nrows==0 || ncolumns==0)
6464+ G_THROW( ERR_MSG("GBitmap.not_init") );
6565++ if (ncolumns + border != (unsigned short)(ncolumns+border))
6666++ G_THROW("GBitmap: image size exceeds maximum (corrupted file?)");
6767+ bytes_per_row = ncolumns + border;
6868+ if (runs==0)
6969+ G_THROW( ERR_MSG("GBitmap.null_arg") );
7070+diff --git a/libdjvu/IW44Image.cpp b/libdjvu/IW44Image.cpp
7171+index e8d4b44..4a1797e 100644
7272+--- a/libdjvu/IW44Image.cpp
7373++++ b/libdjvu/IW44Image.cpp
7474+@@ -676,9 +676,13 @@ IW44Image::Map::image(signed char *img8, int rowsize, int pixsep, int fast)
7575+ // Allocate reconstruction buffer
7676+ short *data16;
7777+ size_t sz = bw * bh;
7878++ if (sz == 0)
7979++ G_THROW("IW44Image: image size is zero (corrupted file?)");
8080+ if (sz / (size_t)bw != (size_t)bh) // multiplication overflow
8181+ G_THROW("IW44Image: image size exceeds maximum (corrupted file?)");
8282+ GPBuffer<short> gdata16(data16,sz);
8383++ if (data16 == 0)
8484++ G_THROW("IW44Image: unable to allocate image buffer");
8585+ // Copy coefficients
8686+ int i;
8787+ short *p = data16;
8888+diff --git a/tools/ddjvu.cpp b/tools/ddjvu.cpp
8989+index 7109952..e7b489b 100644
9090+--- a/tools/ddjvu.cpp
9191++++ b/tools/ddjvu.cpp
9292+@@ -393,8 +393,11 @@ render(ddjvu_page_t *page, int pageno)
9393+ } else if (style == DDJVU_FORMAT_GREY8)
9494+ rowsize = rrect.w;
9595+ else
9696+- rowsize = rrect.w * 3;
9797+- if (! (image = (char*)malloc(rowsize * rrect.h)))
9898++ rowsize = rrect.w * 3;
9999++ size_t bufsize = (size_t)rowsize * rrect.h;
100100++ if (bufsize / rowsize != rrect.h)
101101++ die(i18n("Integer overflow when allocating image buffer for page %d"), pageno);
102102++ if (! (image = (char*)malloc(bufsize)))
103103+ die(i18n("Cannot allocate image buffer for page %d"), pageno);
104104+105105+ /* Render */
+8-4
pkgs/applications/misc/djvulibre/default.nix
···3030 bash
3131 ];
32323333- # Remove uses of the `register` storage class specifier, which was removed in C++17.
3434- # Fixes compilation with clang 16, which defaults to C++17.
3535- patches = [ ./c++17-register-class.patch ];
3333+ enableParallelBuilding = true;
36343737- enableParallelBuilding = true;
3535+ patches = [
3636+ # Remove uses of the `register` storage class specifier, which was removed in C++17.
3737+ # Fixes compilation with clang 16, which defaults to C++17.
3838+ ./c++17-register-class.patch
3939+4040+ ./CVE-2021-3500+CVE-2021-32490+CVE-2021-32491+CVE-2021-32492+CVE-2021-32493.patch
4141+ ];
38423943 meta = with lib; {
4044 description = "The big set of CLI tools to make/modify/optimize/show/export DJVU files";