Browse Source

Cherry-pick various fixes after the 5.43 release

* Adjust degas to co-exist with Adobe Photoshop Color (Joerg Jenderek)
* Handle negative numbers in overflow calculation
* Comment out DEGAS entries because they get mixed with python pickle files
* For indirect magic, reset printed_something and need_separator so that (...)
* Maintain firstline correctly
Christoph Biedl 1 year ago
parent
commit
f9bee1b87d

+ 49 - 0
debian/patches/1663939282.FILE5_43-31-g409d43bb.adjust-degas-to-co-exist-with-adobe-photoshop-color-joerg-jenderek.patch

@@ -0,0 +1,49 @@
+Subject: Adjust degas to co-exist with Adobe Photoshop Color (Joerg Jenderek)
+Origin: FILE5_43-31-g409d43bb <https://github.com/file/file/commit/FILE5_43-31-g409d43bb>
+Upstream-Author: Christos Zoulas <christos@zoulas.com>
+Date: Fri Sep 23 13:21:22 2022 +0000
+
+--- a/magic/Magdir/images
++++ b/magic/Magdir/images
+@@ -1459,22 +1459,22 @@
+ # skip g3test.g3 by test for unused bits of 2nd color entry
+ >>4		ubeshort&0xF000	0
+ #>>>0		beshort	x	1ST_VALUE=%x
+->>>-0		offset	x	FILE_SIZE=%lld
++#>>>-0		offset	x	FILE_SIZE=%lld
+ # standard DEGAS low-res uncompressed bitmap *.pi1 with file size 32034
+->>>-0		offset	=32034	VARIANT_STANDARD
++>>>-0		offset	=32034
+ #>>>>0		beshort	x	1st_VALUE=%x
+ # like: 8ball.pi1 teddy.pi1 sonic01.pi1 
+ >>>>0		use		degas-bitmap
+ # about 61 DEGAS Elite low-res uncompressed bitmap *.pi1 with file size 32066
+->>>-0		offset	=32066	VARIANT_ELITE
++>>>-0		offset	=32066
+ # like: spider.pi1 pinkgirl.pi1 frog3.pi1
+ >>>>0		use		degas-bitmap
+ # about 55 DEGAS Elite low-res uncompressed bitmap *.pi1 with file size 32128
+->>>-0		offset	=32128	VARIANT_3
++>>>-0		offset	=32128
+ # like: mountain.pi1 bigspid.pi1 alf33.pi1
+ >>>>0		use		degas-bitmap
+ # 1 DEGAS Elite low-res uncompressed bitmap *.pi1 with file size 44834
+->>>-0		offset	=44834	VARIANT_4
++>>>-0		offset	=44834
+ # like: kenshin.pi1
+ >>>>0		use		degas-bitmap
+ # DEGAS mid-res uncompressed bitmap *.pi2 (strength=50) after GEM Images like:
+@@ -1515,8 +1515,12 @@
+ # 00000000 "LEREDACT.PI3" 03730773 "TBX_DEMO.PI3"
+ #>>>>&8		ubelong			x	\b, LAST CHAR+NIL %8.8x
+ >>>>&8		ubelong&0xff00ffFF	!0
++# skip many Adobe Photoshop Color swatch (ANPA-Farben.aco TOYO-Farbsystem.aco) with invalid 3rd color entry (1319 2201 2206 21f5 2480 24db 25fd)
++>>>>>6		ubeshort&0xF000	0
++# skip few Adobe Photoshop Color swatch (FOCOLTONE-Farben.aco "PANTONE process coated.aco") with invalid 4th color entry  (ffff)
++>>>>>>8		ubeshort&0xF000	0
+ # many DEGAS bitmap like: ARABDEMO.PI3 ELMRSESN.PI3 GEMVIEW.PI3 LEREDACT.PI3 PICCOLO.PI3 REPRO_JR.PI3 ST_TOOLS.PI3 TBX_DEMO.PI3 evgem7.pi3
+->>>>>0		use		degas-bitmap
++>>>>>>>0	use		degas-bitmap
+ # test for last character of Adobe PhotoShop Brush UTF16-LE string and terminating nul char
+ >>>>&8		ubelong&0xff00ffFF	=0
+ # select last DEGAS bitmaps by invalid last char of brush note like BASICNES.PI3 DB_HELP.PI3 DB_WRITR.PI3 LEREDACT.PI3

+ 42 - 0
debian/patches/1664724087.FILE5_43-55-gbd3cac67.handle-negative-numbers-in-overflow-calculation.patch

@@ -0,0 +1,42 @@
+Subject: Handle negative numbers in overflow calculation
+Origin: FILE5_43-55-gbd3cac67 <https://github.com/file/file/commit/FILE5_43-55-gbd3cac67>
+Upstream-Author: Christos Zoulas <christos@zoulas.com>
+Date: Sun Oct 2 15:21:27 2022 +0000
+
+--- a/src/apprentice.c
++++ b/src/apprentice.c
+@@ -2832,6 +2832,7 @@
+ {
+ 	char *ep;
+ 	uint64_t ull;
++	int y;
+ 
+ 	switch (m->type) {
+ 	case FILE_BESTRING16:
+@@ -2916,21 +2917,25 @@
+ 			switch (ts) {
+ 			case 1:
+ 				x = CAST(uint64_t, ull & ~0xffULL);
++				y = (x & ~0xffULL) != ~0xffULL;
+ 				break;
+ 			case 2:
+ 				x = CAST(uint64_t, ull & ~0xffffULL);
++				y = (x & ~0xffffULL) != ~0xffffULL;
+ 				break;
+ 			case 4:
+ 				x = CAST(uint64_t, ull & ~0xffffffffULL);
++				y = (x & ~0xffffffffULL) != ~0xffffffffULL;
+ 				break;
+ 			case 8:
+ 				x = 0;
++				y = 0;
+ 				break;
+ 			default:
+ 				fprintf(stderr, "Bad width %zu", ts);
+ 				abort();
+ 			}
+-			if (x) {
++			if (x && y) {
+ 				file_magwarn(ms, "Overflow for numeric"
+ 				    " type `%s' value %#" PRIx64,
+ 				    type_tbl[m->type].name, ull);

+ 34 - 0
debian/patches/1665164526.FILE5_43-57-g39ef647c.comment-out-degas-entries-because-they-get-mixed-with-python-pickle-files.patch

@@ -0,0 +1,34 @@
+Subject: Comment out DEGAS entries because they get mixed with python pickle files
+Origin: FILE5_43-57-g39ef647c <https://github.com/file/file/commit/FILE5_43-57-g39ef647c>
+Upstream-Author: Christos Zoulas <christos@zoulas.com>
+Date: Fri Oct 7 17:42:06 2022 +0000
+
+--- a/magic/Magdir/images
++++ b/magic/Magdir/images
+@@ -1528,17 +1528,19 @@
+ >>>>>>0		use		degas-bitmap
+ # last character of Adobe PhotoShop Brush UTF16-LE note
+ #>>>>>&-4	ubelong&0x00FF0000	>0x001F0000	\b, THAT IS ABR
++
++# Commented out because they are weak
+ # DEGAS low-res compressed bitmap *.pc1 like: BATTLSHP.PC1 GNUCHESS.PC1 MEDUSABL.PC1 MOONLORD.PC1 WILDROSE.PC1
+-0		beshort			0x8000
++#0		beshort			0x8000
+ # skip lif files handled via ./lif by test for unused bits of 1st palette entry
+->2		ubeshort&0xF000		0
+->>0		use		degas-bitmap
++#>2		ubeshort&0xF000		0
++#>>0		use		degas-bitmap
+ # DEGAS mid-res compressed bitmap *.pc2 like: abydos.pc2 ARTIS3.PC2 SMTHDRAW.PC2 STAR_2K.PC2 TX2_DEMO.PC2
+-0		beshort			0x8001
+->0		use		degas-bitmap
++#0		beshort			0x8001
++#>0		use		degas-bitmap
+ # DEGAS high-res compressed bitmap *.pc3 like: abydos.pc3 COYOTE.PC3 ELEPHANT.PC3 TX2_DEMO.PC3 SMTHDRAW.PC3
+-0		beshort			0x8002
+->0		use		degas-bitmap
++#0		beshort			0x8002
++#>0		use		degas-bitmap
+ # display information of Atari DEGAS and DEGAS Elite bitmap images
+ 0	name		degas-bitmap
+ >0	ubyte		x		Atari DEGAS

+ 27 - 0
debian/patches/1665168050.FILE5_43-59-ga960a2ad.for-indirect-magic-reset-printed-something-and-need-separator-so-that.patch

@@ -0,0 +1,27 @@
+Subject: For indirect magic, reset printed_something and need_separator so that (...)
+Origin: FILE5_43-59-ga960a2ad <https://github.com/file/file/commit/FILE5_43-59-ga960a2ad>
+Upstream-Author: Christos Zoulas <christos@zoulas.com>
+Date: Fri Oct 7 18:40:50 2022 +0000
+
+    for indirect magic, reset printed_something and need_separator so that
+    we don't trigger printing a separator (Christoph Biedl)
+
+--- a/src/softmagic.c
++++ b/src/softmagic.c
+@@ -1860,11 +1860,15 @@
+ 		for (mlp = ms->mlist[0]->next; mlp != ms->mlist[0];
+ 		    mlp = mlp->next)
+ 		{
++			int xprinted_something = 0;
++			int xneed_separator = 0;
+ 			if ((rv = match(ms, mlp->magic, mlp->magic_rxcomp,
+ 			    mlp->nmagic, &bb, 0, BINTEST, text, 0, indir_count,
+-			    name_count, printed_something, need_separator,
++			    name_count, &xprinted_something, &xneed_separator,
+ 			    NULL, NULL)) != 0)
+ 				break;
++			*printed_something |= xprinted_something;
++			*need_separator |= xneed_separator;
+ 		}
+ 
+ 		if ((ms->flags & MAGIC_DEBUG) != 0)

+ 166 - 0
debian/patches/1665324403.FILE5_43-63-g3503cc0c.maintain-firstline-correctly.patch

@@ -0,0 +1,166 @@
+Subject: Maintain firstline correctly
+Origin: FILE5_43-63-g3503cc0c <https://github.com/file/file/commit/FILE5_43-63-g3503cc0c>
+Upstream-Author: Christos Zoulas <christos@zoulas.com>
+Date: Sun Oct 9 14:06:43 2022 +0000
+
+--- a/src/softmagic.c
++++ b/src/softmagic.c
+@@ -45,11 +45,11 @@
+ 
+ private int match(struct magic_set *, struct magic *, file_regex_t **, size_t,
+     const struct buffer *, size_t, int, int, int, uint16_t *,
+-    uint16_t *, int *, int *, int *, int *);
++    uint16_t *, int *, int *, int *, int *, int *);
+ private int mget(struct magic_set *, struct magic *, const struct buffer *,
+     const unsigned char *, size_t,
+     size_t, unsigned int, int, int, int, uint16_t *,
+-    uint16_t *, int *, int *, int *, int *);
++    uint16_t *, int *, int *, int *, int *, int *);
+ private int msetoffset(struct magic_set *, struct magic *, struct buffer *,
+     const struct buffer *, size_t, unsigned int);
+ private int magiccheck(struct magic_set *, struct magic *, file_regex_t **);
+@@ -118,7 +118,7 @@
+     uint16_t *indir_count, uint16_t *name_count, int mode, int text)
+ {
+ 	struct mlist *ml;
+-	int rv = 0, printed_something = 0, need_separator = 0;
++	int rv = 0, printed_something = 0, need_separator = 0, firstline = 1;
+ 	uint16_t nc, ic;
+ 
+ 	if (name_count == NULL) {
+@@ -133,7 +133,8 @@
+ 	for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next) {
+ 		int ret = match(ms, ml->magic, ml->magic_rxcomp, ml->nmagic, b,
+ 		    0, mode, text, 0, indir_count, name_count,
+-		    &printed_something, &need_separator, NULL, NULL);
++		    &printed_something, &need_separator, &firstline,
++		    NULL, NULL);
+ 		switch (ret) {
+ 		case -1:
+ 			return ret;
+@@ -205,15 +206,13 @@
+ match(struct magic_set *ms, struct magic *magic, file_regex_t **magic_rxcomp,
+     size_t nmagic, const struct buffer *b, size_t offset, int mode, int text,
+     int flip, uint16_t *indir_count, uint16_t *name_count,
+-    int *printed_something, int *need_separator, int *returnval,
+-    int *found_match)
++    int *printed_something, int *need_separator, int *firstline,
++    int *returnval, int *found_match)
+ {
+ 	uint32_t magindex = 0;
+ 	unsigned int cont_level = 0;
+ 	int found_matchv = 0; /* if a match is found it is set to 1*/
+ 	int returnvalv = 0, e;
+-	/* a flag to print X\n  X\n- X */
+-	int firstline = !(*printed_something || *need_separator);
+ 	struct buffer bb;
+ 	int print = (ms->flags & MAGIC_NODESC) == 0;
+ 
+@@ -257,7 +256,8 @@
+ 		switch (mget(ms, m, b, CAST(const unsigned char *, bb.fbuf),
+ 		    bb.flen, offset, cont_level,
+ 		    mode, text, flip, indir_count, name_count,
+-		    printed_something, need_separator, returnval, found_match))
++		    printed_something, need_separator, firstline, returnval,
++		    found_match))
+ 		{
+ 		case -1:
+ 			return -1;
+@@ -290,7 +290,7 @@
+ 			goto flush;
+ 		}
+ 
+-		if ((e = handle_annotation(ms, m, firstline)) != 0)
++		if ((e = handle_annotation(ms, m, *firstline)) != 0)
+ 		{
+ 			*found_match = 1;
+ 			*need_separator = 1;
+@@ -309,7 +309,7 @@
+ 				*returnval = 1;
+ 				*need_separator = 1;
+ 				*printed_something = 1;
+-				if (print_sep(ms, firstline) == -1)
++				if (print_sep(ms, *firstline) == -1)
+ 					return -1;
+ 				if (mprint(ms, m) == -1)
+ 					return -1;
+@@ -368,7 +368,7 @@
+ 			    bb.fbuf), bb.flen, offset,
+ 			    cont_level, mode, text, flip, indir_count,
+ 			    name_count, printed_something, need_separator,
+-			    returnval, found_match)) {
++			    firstline, returnval, found_match)) {
+ 			case -1:
+ 				return -1;
+ 			case 0:
+@@ -405,7 +405,7 @@
+ 				} else
+ 					ms->c.li[cont_level].got_match = 1;
+ 
+-				if ((e = handle_annotation(ms, m, firstline))
++				if ((e = handle_annotation(ms, m, *firstline))
+ 				    != 0) {
+ 					*found_match = 1;
+ 					*need_separator = 1;
+@@ -431,7 +431,7 @@
+ 					 */
+ 					if (!*printed_something) {
+ 						*printed_something = 1;
+-						if (print_sep(ms, firstline)
++						if (print_sep(ms, *firstline)
+ 						    == -1)
+ 							return -1;
+ 					}
+@@ -467,14 +467,14 @@
+ 			}
+ 		}
+ 		if (*printed_something) {
+-			firstline = 0;
++			*firstline = 0;
+ 		}
+ 		if (*found_match) {
+ 			if ((ms->flags & MAGIC_CONTINUE) == 0)
+ 				return *returnval;
+ 			// So that we print a separator
+ 			*printed_something = 0;
+-			firstline = 0;
++			*firstline = 0;
+ 		}
+ 		cont_level = 0;
+ 	}
+@@ -1564,7 +1564,7 @@
+ mget(struct magic_set *ms, struct magic *m, const struct buffer *b,
+     const unsigned char *s, size_t nbytes, size_t o, unsigned int cont_level,
+     int mode, int text, int flip, uint16_t *indir_count, uint16_t *name_count,
+-    int *printed_something, int *need_separator, int *returnval,
++    int *printed_something, int *need_separator, int *firstline, int *returnval,
+     int *found_match)
+ {
+ 	uint32_t eoffset, offset = ms->offset;
+@@ -1860,15 +1860,11 @@
+ 		for (mlp = ms->mlist[0]->next; mlp != ms->mlist[0];
+ 		    mlp = mlp->next)
+ 		{
+-			int xprinted_something = 0;
+-			int xneed_separator = 0;
+ 			if ((rv = match(ms, mlp->magic, mlp->magic_rxcomp,
+ 			    mlp->nmagic, &bb, 0, BINTEST, text, 0, indir_count,
+-			    name_count, &xprinted_something, &xneed_separator,
+-			    NULL, NULL)) != 0)
++			    name_count, printed_something, need_separator,
++			    firstline, NULL, NULL)) != 0)
+ 				break;
+-			*printed_something |= xprinted_something;
+-			*need_separator |= xneed_separator;
+ 		}
+ 
+ 		if ((ms->flags & MAGIC_DEBUG) != 0)
+@@ -1919,7 +1915,7 @@
+ 		eoffset = ms->eoffset;
+ 		rv = match(ms, ml.magic, ml.magic_rxcomp, ml.nmagic, b,
+ 		    offset + o, mode, text, flip, indir_count, name_count,
+-		    printed_something, need_separator, returnval,
++		    printed_something, need_separator, firstline, returnval,
+ 		    &nfound_match);
+ 		ms->ms_value.q = nfound_match;
+ 		(*name_count)--;

+ 5 - 0
debian/patches/series

@@ -1,6 +1,11 @@
 # reverted upstream commits
 
 # cherry-picked commits. Keep in upstream's chronological order
+1663939282.FILE5_43-31-g409d43bb.adjust-degas-to-co-exist-with-adobe-photoshop-color-joerg-jenderek.patch
+1664724087.FILE5_43-55-gbd3cac67.handle-negative-numbers-in-overflow-calculation.patch
+1665164526.FILE5_43-57-g39ef647c.comment-out-degas-entries-because-they-get-mixed-with-python-pickle-files.patch
+1665168050.FILE5_43-59-ga960a2ad.for-indirect-magic-reset-printed-something-and-need-separator-so-that.patch
+1665324403.FILE5_43-63-g3503cc0c.maintain-firstline-correctly.patch
 
 # patches that should go upstream
 upstream.disable.att3b.patch