[File] Misidentified python script

Steve Grubb sgrubb at redhat.com
Tue Mar 3 02:01:18 UTC 2020


Hello,

On Monday, March 2, 2020 10:14:00 AM EST Steve Grubb wrote:
> I can see how it is matching the from and then import. However, I think the
> regex is assuming too much. You cannot have a carriage return between from
> and import and whatever python module you are importing. You get something
> like this if you do:
> 
>   File "./test.py", line 2
>     import
>          ^
> SyntaxError: invalid syntax
> 
> I don't know if anything can be done about this since it is suspiciously
> close to actual code

After testing all day, the following patch fixes it for me. Bottom line,
python doesn't tolerate \f\r\n  between certain keywords.

Best Regards,
-Steve


diff --git a/magic/Magdir/python b/magic/Magdir/python
index 39fd3aec..f24e469e 100644
--- a/magic/Magdir/python
+++ b/magic/Magdir/python
@@ -90,7 +90,7 @@
 
 # from module.submodule import func1, func2
 0	search/8192	import
->0	regex		\^from[\040\t\f\r\n]+([A-Za-z0-9_]|\\.)+[\040\t\f\r\n]+import.*$	Python script text executable
+>0	regex		\^from[\040\t]+([A-Za-z0-9_]|\\.)+[\040\t]+import.*$	Python script text executable
 !:strength + 15
 !:mime text/x-script.python
 






More information about the File mailing list