Skip to content

Commit 855bbc8

Browse files
Joshua Westerheideweltling
authored andcommitted
Fix #78183: finfo_file shows wrong mime-type for .tga file
Due to a bug in the underlying libmagic 5.31, .tga images returned mime type "image/x-tgaimage/x-tga".
1 parent f7327b6 commit 855bbc8

File tree

6 files changed

+52788
-52725
lines changed

6 files changed

+52788
-52725
lines changed

ext/fileinfo/data_file.c

Lines changed: 52722 additions & 52701 deletions
Large diffs are not rendered by default.

ext/fileinfo/magicdata.patch

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,41 @@ index 69e8e90f..76f7e7da 100644
180180
--
181181
2.13.6
182182

183+
From bb421c437d406760fb9f70f49e2eb5c504528450 Mon Sep 17 00:00:00 2001
184+
From: Christos Zoulas <[email protected]>
185+
Date: Mon, 5 Jun 2017 17:40:31 +0000
186+
Subject: [PATCH] use default to avoid dup printing (Stephan Kulow)
187+
188+
---
189+
magic/Magdir/images | 13 +++++++------
190+
1 file changed, 7 insertions(+), 6 deletions(-)
191+
192+
diff --git a/magic/Magdir/images b/magic/Magdir/images
193+
index d14c1de19..7e6f74d5e 100644
194+
--- a/magic/Magdir/images
195+
+++ b/magic/Magdir/images
196+
@@ -35,11 +35,6 @@
197+
>>>16 ubyte <33
198+
# skip more by looking for pixel size 0Fh 10h 18h 20h
199+
>>>>16 ubyte&0xC0 0x00
200+
-# skip 260-16.ico by looking for no color map
201+
->>>>>1 ubyte 0
202+
-# implies no first map entry
203+
->>>>>>3 uleshort 0
204+
->>>>>>>0 use tga-image
205+
# Color Map
206+
>>>>>1 belong&0xfff7ffff 0x01010000
207+
>>>>>>0 use tga-image
208+
@@ -47,6 +42,12 @@
209+
>>>>>>0 use tga-image
210+
>>>>>1 belong&0xfff7ffff 0x00030000
211+
>>>>>>0 use tga-image
212+
+>>>>>1 default x
213+
+# skip 260-16.ico by looking for no color map
214+
+>>>>>>1 ubyte 0
215+
+# implies no first map entry
216+
+>>>>>>>3 uleshort 0
217+
+>>>>>>>>0 use tga-image
218+
# display tga bitmap image information
219+
0 name tga-image
220+
>2 ubyte <34 Targa image data

ext/fileinfo/tests/finfo_file_002.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ksort($results);
1818
var_dump($results);
1919
?>
2020
--EXPECTF--
21-
array(9) {
21+
array(10) {
2222
["%s/resources/dir.zip"]=>
2323
string(15) "application/zip"
2424
["%s/resources/test.awk"]=>
@@ -37,4 +37,6 @@ array(9) {
3737
string(9) "image/png"
3838
["%s/resources/test.ppt"]=>
3939
string(29) "application/vnd.ms-powerpoint"
40+
["%s/resources/test.tga"]=>
41+
string(11) "image/x-tga"
4042
}

ext/fileinfo/tests/magic

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@
16821682
# http://home.earthlink.net/~hughhood/appleiiworksenvoy/
16831683
# ('p' + 1-byte ProDOS File Type + 2-byte ProDOS Aux Type')
16841684
# $70 $1A $F8 $FF is this the apple type ?
1685-
#:apple pdosp��
1685+
#:apple pdosp��
16861686
!:ext awp
16871687
# minimum version needed to read this files. SFMinVers (0 , 30~3.0 )
16881688
>>>183 ubyte 30 3.0
@@ -7299,9 +7299,9 @@
72997299
#>>52 ulelong 3 \b, CleanShutdown
73007300
>>52 ulelong 4 \b, BeingConverted
73017301
>>52 ulelong 5 \b, ForceDetach
7302-
# Windows�NT major version when the databases indexes were updated.
7302+
# Windows�NT major version when the databases indexes were updated.
73037303
>>216 ulelong x \b, Windows version %d
7304-
# Windows�NT minor version
7304+
# Windows�NT minor version
73057305
>>220 ulelong x \b.%d
73067306

73077307
# From: Joerg Jenderek
@@ -13280,18 +13280,19 @@
1328013280
>>>16 ubyte <33
1328113281
# skip more by looking for pixel size 0Fh 10h 18h 20h
1328213282
>>>>16 ubyte&0xC0 0x00
13283-
# skip 260-16.ico by looking for no color map
13284-
>>>>>1 ubyte 0
13285-
# implies no first map entry
13286-
>>>>>>3 uleshort 0
13287-
>>>>>>>0 use tga-image
1328813283
# Color Map
1328913284
>>>>>1 belong&0xfff7ffff 0x01010000
1329013285
>>>>>>0 use tga-image
1329113286
>>>>>1 belong&0xfff7ffff 0x00020000
1329213287
>>>>>>0 use tga-image
1329313288
>>>>>1 belong&0xfff7ffff 0x00030000
1329413289
>>>>>>0 use tga-image
13290+
>>>>>1 default x
13291+
# skip 260-16.ico by looking for no color map
13292+
>>>>>>1 ubyte 0
13293+
# implies no first map entry
13294+
>>>>>>>3 uleshort 0
13295+
>>>>>>>>0 use tga-image
1329513296
# display tga bitmap image information
1329613297
0 name tga-image
1329713298
>2 ubyte <34 Targa image data

ext/fileinfo/tests/magic私はガラスを食べられます

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@
16821682
# http://home.earthlink.net/~hughhood/appleiiworksenvoy/
16831683
# ('p' + 1-byte ProDOS File Type + 2-byte ProDOS Aux Type')
16841684
# $70 $1A $F8 $FF is this the apple type ?
1685-
#:apple pdosp��
1685+
#:apple pdosp��
16861686
!:ext awp
16871687
# minimum version needed to read this files. SFMinVers (0 , 30~3.0 )
16881688
>>>183 ubyte 30 3.0
@@ -7299,9 +7299,9 @@
72997299
#>>52 ulelong 3 \b, CleanShutdown
73007300
>>52 ulelong 4 \b, BeingConverted
73017301
>>52 ulelong 5 \b, ForceDetach
7302-
# Windows�NT major version when the databases indexes were updated.
7302+
# Windows�NT major version when the databases indexes were updated.
73037303
>>216 ulelong x \b, Windows version %d
7304-
# Windows�NT minor version
7304+
# Windows�NT minor version
73057305
>>220 ulelong x \b.%d
73067306

73077307
# From: Joerg Jenderek
@@ -13280,18 +13280,19 @@
1328013280
>>>16 ubyte <33
1328113281
# skip more by looking for pixel size 0Fh 10h 18h 20h
1328213282
>>>>16 ubyte&0xC0 0x00
13283-
# skip 260-16.ico by looking for no color map
13284-
>>>>>1 ubyte 0
13285-
# implies no first map entry
13286-
>>>>>>3 uleshort 0
13287-
>>>>>>>0 use tga-image
1328813283
# Color Map
1328913284
>>>>>1 belong&0xfff7ffff 0x01010000
1329013285
>>>>>>0 use tga-image
1329113286
>>>>>1 belong&0xfff7ffff 0x00020000
1329213287
>>>>>>0 use tga-image
1329313288
>>>>>1 belong&0xfff7ffff 0x00030000
1329413289
>>>>>>0 use tga-image
13290+
>>>>>1 default x
13291+
# skip 260-16.ico by looking for no color map
13292+
>>>>>>1 ubyte 0
13293+
# implies no first map entry
13294+
>>>>>>>3 uleshort 0
13295+
>>>>>>>>0 use tga-image
1329513296
# display tga bitmap image information
1329613297
0 name tga-image
1329713298
>2 ubyte <34 Targa image data
@@ -18470,23 +18471,23 @@
1847018471

1847118472
# skip some AppleWorks word like Tomahawk.Awp, WIN98SE-DE.vhd
1847218473
# by looking for trailing nul of maximal file name string
18473-
0x52 ubyte 0
18474+
0x52 ubyte 0
1847418475
# test for flag byte: FFh~complete file, 00h~split file
1847518476
# FFh -127 = -1 -127 = -128
1847618477
# 00h -127 = 0 -127 = -127
1847718478
>0 byte-127 <-126
1847818479
# plausibility check for file name length
18479-
>>0x53 ubyte-1 <78
18480+
>>0x53 ubyte-1 <78
1848018481
# looking for terminating nul of file name string
18481-
>>>(0x53.b+4) ubyte 0
18482+
>>>(0x53.b+4) ubyte 0
1848218483
# looking if last char of string is valid DOS file name
18483-
>>>>(0x53.b+3) ubyte >0x1F
18484+
>>>>(0x53.b+3) ubyte >0x1F
1848418485
# actually 44 nul bytes
1848518486
# but sometimes garbage according to Ralf Quint. So can not be used as test
1848618487
#>0x54 string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
1848718488
# first char of full file name is DOS (5Ch) or UNIX (2Fh) path separator
18488-
# only DOS variant found. UNIX variant according to V32SLASH.TXT in archive PD0315.EXE
18489-
>>>>>5 ubyte&0x8C 0x0C
18489+
# only DOS variant found. UNIX variant according to V32SLASH.TXT in archive PD0315.EXE
18490+
>>>>>5 ubyte&0x8C 0x0C
1849018491
# ./msdos (version 5.30) labeled the entry as
1849118492
# "DOS 2.0 backed up file %s, split file, sequence %d" or
1849218493
# "DOS 2.0 backed up file %s, complete file"
@@ -18501,7 +18502,7 @@
1850118502
# magic/Magdir/msdos, 1169: Warning: EXTENSION type ` *' has bad char '*'
1850218503
# file: line 1169: Bad magic entry ' *'
1850318504
# after header original file content
18504-
>>>>>>128 indirect x \b;
18505+
>>>>>>128 indirect x \b;
1850518506

1850618507

1850718508
# DOS backup 3.3 to 5.x

ext/fileinfo/tests/resources/test.tga

19 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)