From 5f050887d2d11491ecf7f4649a9f3ec6313ac1ef Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Sun, 4 Nov 2012 17:26:58 -0800 Subject: [PATCH] Rebase for file 5.32 Change-Id: I2e18bd02d44bc28edd5c98ba25b037e8c451421b Signed-off-by: DongHun Kwak --- magic/Magdir/jpeg | 116 ++++++++++++++++++++++++++++------ magic/Makefile.am | 2 +- packaging/baselibs.conf | 1 + packaging/file.changes | 12 ++++ packaging/file.manifest | 5 ++ packaging/file.spec | 132 +++++++++++++++++++++++++++++++++++++++ packaging/python-magic-rpmlintrc | 1 + packaging/python-magic.spec | 43 +++++++++++++ python/magic.py | 13 +++- src/compress.c | 2 +- src/readcdf.c | 2 +- 11 files changed, 305 insertions(+), 24 deletions(-) create mode 100644 packaging/baselibs.conf create mode 100644 packaging/file.changes create mode 100644 packaging/file.manifest create mode 100644 packaging/file.spec create mode 100644 packaging/python-magic-rpmlintrc create mode 100644 packaging/python-magic.spec diff --git a/magic/Magdir/jpeg b/magic/Magdir/jpeg index 57adb1e..9aff2c5 100644 --- a/magic/Magdir/jpeg +++ b/magic/Magdir/jpeg @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------ -# $File: jpeg,v 1.31 2017/03/17 21:35:28 christos Exp $ +# $File: jpeg,v 1.20 2014/08/05 07:32:31 christos Exp $ # JPEG images # SunOS 5.5.1 had # @@ -12,8 +12,7 @@ 0 beshort 0xffd8 JPEG image data !:mime image/jpeg !:apple 8BIMJPEG -!:strength *3 -!:ext jpeg/jpg/jpe/jfif +!:strength +2 >6 string JFIF \b, JFIF standard # The following added by Erik Rossen 1999-09-06 # in a vain attempt to add image size reporting for JFIF. Note that these @@ -32,9 +31,98 @@ # Next, show thumbnail info, if it exists: >>18 byte !0 \b, thumbnail %dx >>>19 byte x \b%d ->6 string Exif \b, Exif standard: [ ->>12 indirect/r x ->>12 string x \b] + +# EXIF moved down here to avoid reporting a bogus version number, +# and EXIF version number printing added. +# - Patrik R=E5dman +>6 string Exif \b, EXIF standard +# Look for EXIF IFD offset in IFD 0, and then look for EXIF version tag in EXIF IFD. +# All possible combinations of entries have to be enumerated, since no looping +# is possible. And both endians are possible... +# The combinations included below are from real-world JPEGs. +# Little-endian +>>12 string II +# IFD 0 Entry #5: +>>>70 leshort 0x8769 +# EXIF IFD Entry #1: +>>>>(78.l+14) leshort 0x9000 +>>>>>(78.l+23) byte x %c +>>>>>(78.l+24) byte x \b.%c +>>>>>(78.l+25) byte !0x30 \b%c +# IFD 0 Entry #9: +>>>118 leshort 0x8769 +# EXIF IFD Entry #3: +>>>>(126.l+38) leshort 0x9000 +>>>>>(126.l+47) byte x %c +>>>>>(126.l+48) byte x \b.%c +>>>>>(126.l+49) byte !0x30 \b%c +# IFD 0 Entry #10 +>>>130 leshort 0x8769 +# EXIF IFD Entry #3: +>>>>(138.l+38) leshort 0x9000 +>>>>>(138.l+47) byte x %c +>>>>>(138.l+48) byte x \b.%c +>>>>>(138.l+49) byte !0x30 \b%c +# EXIF IFD Entry #4: +>>>>(138.l+50) leshort 0x9000 +>>>>>(138.l+59) byte x %c +>>>>>(138.l+60) byte x \b.%c +>>>>>(138.l+61) byte !0x30 \b%c +# EXIF IFD Entry #5: +>>>>(138.l+62) leshort 0x9000 +>>>>>(138.l+71) byte x %c +>>>>>(138.l+72) byte x \b.%c +>>>>>(138.l+73) byte !0x30 \b%c +# IFD 0 Entry #11 +>>>142 leshort 0x8769 +# EXIF IFD Entry #3: +>>>>(150.l+38) leshort 0x9000 +>>>>>(150.l+47) byte x %c +>>>>>(150.l+48) byte x \b.%c +>>>>>(150.l+49) byte !0x30 \b%c +# EXIF IFD Entry #4: +>>>>(150.l+50) leshort 0x9000 +>>>>>(150.l+59) byte x %c +>>>>>(150.l+60) byte x \b.%c +>>>>>(150.l+61) byte !0x30 \b%c +# EXIF IFD Entry #5: +>>>>(150.l+62) leshort 0x9000 +>>>>>(150.l+71) byte x %c +>>>>>(150.l+72) byte x \b.%c +>>>>>(150.l+73) byte !0x30 \b%c +# Big-endian +>>12 string MM +# IFD 0 Entry #9: +>>>118 beshort 0x8769 +# EXIF IFD Entry #1: +>>>>(126.L+14) beshort 0x9000 +>>>>>(126.L+23) byte x %c +>>>>>(126.L+24) byte x \b.%c +>>>>>(126.L+25) byte !0x30 \b%c +# EXIF IFD Entry #3: +>>>>(126.L+38) beshort 0x9000 +>>>>>(126.L+47) byte x %c +>>>>>(126.L+48) byte x \b.%c +>>>>>(126.L+49) byte !0x30 \b%c +# IFD 0 Entry #10 +>>>130 beshort 0x8769 +# EXIF IFD Entry #3: +>>>>(138.L+38) beshort 0x9000 +>>>>>(138.L+47) byte x %c +>>>>>(138.L+48) byte x \b.%c +>>>>>(138.L+49) byte !0x30 \b%c +# EXIF IFD Entry #5: +>>>>(138.L+62) beshort 0x9000 +>>>>>(138.L+71) byte x %c +>>>>>(138.L+72) byte x \b.%c +>>>>>(138.L+73) byte !0x30 \b%c +# IFD 0 Entry #11 +>>>142 beshort 0x8769 +# EXIF IFD Entry #4: +>>>>(150.L+50) beshort 0x9000 +>>>>>(150.L+59) byte x %c +>>>>>(150.L+60) byte x \b.%c +>>>>>(150.L+61) byte !0x30 \b%c # Jump to the first segment >(4.S+4) use jpeg_segment @@ -42,8 +130,7 @@ # This uses recursion... 0 name jpeg_segment >0 beshort 0xFFFE -# Recursion handled by FFE0 -#>>(2.S+2) use jpeg_segment +>>(2.S+2) use jpeg_segment >>2 pstring/HJ x \b, comment: "%s" >0 beshort 0xFFC0 @@ -71,13 +158,6 @@ >0 beshort 0xFFC4 >>(2.S+2) use jpeg_segment ->0 beshort 0xFFE1 -# Recursion handled by FFE0 -#>>(2.S+2) use jpeg_segment ->>4 string Exif \b, Exif Standard: [ ->>>10 indirect/r x ->>>10 string x \b] - # Application specific markers >0 beshort&0xFFE0 =0xFFE0 >>(2.S+2) use jpeg_segment @@ -88,11 +168,7 @@ # D9: End of image # Dn: Restart >0 beshort&0xFFD0 =0xFFD0 ->>0 beshort&0xFFE0 !0xFFE0 ->>>(2.S+2) use jpeg_segment - -#>0 beshort x unknown 0x%x -#>>(2.S+2) use jpeg_segment +>>(2.S+2) use jpeg_segment # HSI is Handmade Software's proprietary JPEG encoding scheme 0 string hsi1 JPEG image data, HSI proprietary diff --git a/magic/Makefile.am b/magic/Makefile.am index 5259a47..027951e 100644 --- a/magic/Makefile.am +++ b/magic/Makefile.am @@ -322,5 +322,5 @@ ${MAGIC}: $(EXTRA_DIST) $(FILE_COMPILE_DEP) exit 1; \ fi; \ fi) - $(FILE_COMPILE) -C -m magic + LD_LIBRARY_PATH=../src/.libs $(FILE_COMPILE) -C -m magic @rm -fr magic diff --git a/packaging/baselibs.conf b/packaging/baselibs.conf new file mode 100644 index 0000000..8e7ce75 --- /dev/null +++ b/packaging/baselibs.conf @@ -0,0 +1 @@ +libmagic diff --git a/packaging/file.changes b/packaging/file.changes new file mode 100644 index 0000000..8c1bae6 --- /dev/null +++ b/packaging/file.changes @@ -0,0 +1,12 @@ +* Wed Nov 6 2013 Ronan Le Martret 7d17da5 +- Fix python-magic build. (PTREL-158) + +* Sat Jun 29 2013 Alexandru Cornea 4795cb8 +- resetting manifest requested domain to floor + +* Sun Mar 17 2013 Anas Nashif submit/trunk/20121215.172437@b91fca2 +- Update package groups + +* Sat Dec 15 2012 Anas Nashif upstream/5.11@8e6268a +- add python module + diff --git a/packaging/file.manifest b/packaging/file.manifest new file mode 100644 index 0000000..017d22d --- /dev/null +++ b/packaging/file.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/file.spec b/packaging/file.spec new file mode 100644 index 0000000..767a833 --- /dev/null +++ b/packaging/file.spec @@ -0,0 +1,132 @@ +%global _miscdir %{_datadir}/misc + +Name: file +BuildRequires: findutils +BuildRequires: libtool +BuildRequires: zlib-devel +Url: http://www.darwinsys.com/file/ +Version: 5.31 +Release: 0 +Summary: A Tool to Determine File Types +License: BSD-2.0 +Group: System/Utilities + +### SOURCES BEGIN ### +Source2: baselibs.conf +Source1001: file.manifest +### SOURCES END ### +Source: ftp://ftp.astron.com/pub/file/file-%{version}.tar.gz + +%description +With the file command, you can obtain information on the file type of a +specified file. File type recognition is controlled by the file +/etc/magic, which contains the classification criteria. This command is +used by apsfilter to permit automatic printing of different file types. + +%package -n libmagic-data +Summary: The magic files for libmagic to use +Group: System/Libraries + +%description -n libmagic-data +This package contains the basic magic files that libmagic reads and uses +to estimate a file's type. + +%package -n libmagic +Summary: Library with file's functionality +Group: System/Libraries +Requires: libmagic-data = %{version} +Provides: libfile +Obsoletes: libfile =< 5.04 + +%description -n libmagic +This library reads magic files and detects file types. Used by file command + +%package -n file-devel +Summary: Include Files and Libraries mandatory for Development +Group: System/Libraries +Provides: file:/usr/include/magic.h +Requires: glibc-devel +Requires: libmagic = %{version} + +%description -n file-devel +This package contains all necessary include files and libraries needed +to develop applications that require the magic "file" interface. + +%prep +%setup -q -n file-%{version} +### PREP BEGIN ### +cp %{SOURCE1001} . +### PREP END ### + +%build +### BUILD BEGIN ### +export LANG=POSIX +export LC_ALL=POSIX +rm -f Magdir/*,v Magdir/*~ +rm -f ltcf-c.sh ltconfig ltmain.sh +autoreconf -fiv +CFLAGS="$RPM_OPT_FLAGS -DHOWMANY=69632" +%configure --disable-silent-rules --datadir=%{_miscdir} --disable-static --with-pic --enable-fsect-man5 +sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool +sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool + +%{__make} %{?_smp_mflags} pkgdatadir='$(datadir)' +%if 0%{?build_python_bindings:1} +pushd python +python setup.py build +popd +%endif +### BUILD END ### + +%install +export LANG=POSIX +export LC_ALL=POSIX +mkdir %{buildroot}%{_sysconfdir} +make DESTDIR=%{buildroot} install pkgdatadir='$(datadir)' +rm -vf %{buildroot}%{_sysconfdir}/magic +echo '# Localstuff: file(1) magic(5) for locally observed files' > %{buildroot}%{_sysconfdir}/magic +echo '# global magic file is %{_miscdir}/magic(.mgc)' >> %{buildroot}%{_sysconfdir}/magic +%{nil install -s dcore %{buildroot}%{_bindir}} +# Check out that the binary does not bail out: +LD_LIBRARY_PATH=%{buildroot}%{_libdir} +export LD_LIBRARY_PATH +%{buildroot}%{_bindir}/file --version +find %{buildroot}%{_bindir}/file %{_bindir}/ /%{_lib}/ %{_libdir}/ | \ + xargs %{buildroot}%{_bindir}/file -m %{buildroot}%{_miscdir}/magic +unset LD_LIBRARY_PATH +%{__rm} -f %{buildroot}%{_libdir}/*.la + +%post -n libmagic -p /sbin/ldconfig + +%postun -n libmagic -p /sbin/ldconfig + +%files -n libmagic +%manifest %{name}.manifest +%defattr (644,root,root,755) +%license COPYING +%{_libdir}/lib*.so.* + +%files -n libmagic-data +%manifest %{name}.manifest +%defattr (644,root,root,755) +%license COPYING +%config(noreplace) %{_sysconfdir}/magic +#%%{_miscdir}/magic +%{_miscdir}/magic.mgc +%doc %{_mandir}/man5/magic.5.gz + +%files +%manifest %{name}.manifest +%defattr (644,root,root,755) +%{nil %{_bindir}/dcore} +%attr(755,root,root) %{_bindir}/file +%doc %{_mandir}/man1/file.1.gz +%license COPYING + +%files -n file-devel +%manifest %{name}.manifest +%defattr (644,root,root,755) +%{_libdir}/lib*.so +%{_includedir}/magic.h +%doc %{_mandir}/man3/libmagic.3.gz +%license COPYING diff --git a/packaging/python-magic-rpmlintrc b/packaging/python-magic-rpmlintrc new file mode 100644 index 0000000..1b4d915 --- /dev/null +++ b/packaging/python-magic-rpmlintrc @@ -0,0 +1 @@ +addFilter("E: non-standard-group"); diff --git a/packaging/python-magic.spec b/packaging/python-magic.spec new file mode 100644 index 0000000..328c60b --- /dev/null +++ b/packaging/python-magic.spec @@ -0,0 +1,43 @@ +%define build_python_bindings 1 +%global _miscdir %{_datadir}/misc + +Name: python-magic +BuildRequires: findutils +BuildRequires: libtool +BuildRequires: python-devel +BuildRequires: python-setuptools +BuildRequires: zlib-devel +Url: http://www.darwinsys.com/file/ +Version: 5.31 +Release: 0 +Summary: Python module to use libmagic +License: BSD-3-Clause and BSD-4-Clause +Group: Platform Development/Python +Source99: file.spec +BuildArch: noarch + +%{expand:%(sed -n -e '/^### SOURCES BEGIN ###/,/^### SOURCES END ###/p' <%_sourcedir/file.spec)} +Source: ftp://ftp.astron.com/pub/file/file-%{version}.tar.gz + +%description +This package contains the python binding that require the magic "file" +interface. + + +%prep +%setup -q -n file-%{version} +%{expand:%(sed -n -e '/^### PREP BEGIN ###/,/^### PREP END ###/p' <%_sourcedir/file.spec)} + +%build +%{expand:%(sed -n -e '/^### BUILD BEGIN ###/,/^### BUILD END ###/p' <%_sourcedir/file.spec)} + +%install +pushd python +python setup.py install --root=%{buildroot} \ + --prefix=%{_prefix} \ + --record-rpm=../python_files +popd + +%files -f python_files +%defattr(-,root,root) + diff --git a/python/magic.py b/python/magic.py index 662569e..b66005b 100644 --- a/python/magic.py +++ b/python/magic.py @@ -145,7 +145,18 @@ class Magic(object): as a filename or None if an error occurred and the MAGIC_ERROR flag is set. A call to errno() will return the numeric error code. """ - return Magic.__tostr(_file(self._magic_t, Magic.__tobytes(filename))) + if isinstance(filename, bytes): + bi = filename + else: + try: # keep Python 2 compatibility + bi = bytes(filename, 'utf-8') + except TypeError: + bi = bytes(filename) + r = _file(self._magic_t, bi) + if isinstance(r, str): + return r + else: + return str(r).encode('utf-8') def descriptor(self, fd): """ diff --git a/src/compress.c b/src/compress.c index 2f789cd..c6e6f0e 100644 --- a/src/compress.c +++ b/src/compress.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: compress.c,v 1.105 2017/05/25 00:13:03 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.97 2016/05/13 23:02:28 christos Exp $") #endif #include "magic.h" diff --git a/src/readcdf.c b/src/readcdf.c index 80c8d26..b4bb784 100644 --- a/src/readcdf.c +++ b/src/readcdf.c @@ -26,7 +26,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: readcdf.c,v 1.65 2017/04/08 20:58:03 christos Exp $") +FILE_RCSID("@(#)$File: readcdf.c,v 1.56 2016/03/03 22:20:03 christos Exp $") #endif #include -- 2.7.4