Bug 318052 (MONO75018) - [PATCH] Report 'file' is a binary file instead of a source code file
Summary: [PATCH] Report 'file' is a binary file instead of a source code file
Status: RESOLVED FIXED
Alias: MONO75018
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Enhancement
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2005-05-21 19:54 UTC by Ben Maurer
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
Patch (1.29 KB, patch)
2005-05-21 20:24 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:18:12 UTC


---- Reported by bmaurer@users.sf.net 2005-05-21 12:54:34 MST ----

According to MSDN:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cscomp/html/vcerrCompilerErrorSC2015.asp

Compiler Error CS2015
'file' is a binary file instead of a source code file

A file was passed to the compiler that was a binary file. The compiler
expects a source code file.

This is really helpful when you say:

mcs foo.exe

Rather than

mcs foo.cs

Not sure how this would be detected though.



---- Additional Comments From bmaurer@users.sf.net 2005-05-21 13:08:59 MST ----

One really easy way to detect this is to read the first N bytes and
see if any of them contain the null byte. Assuming the file is random,
if we read the first 4 kb of the file, the chance that it would escape
this test is

(255/256)^(4*1024)=0.000000109

It also looks like all .exe files will have a \0 in their first few
bytes, so they would all be detected.



---- Additional Comments From bmaurer@users.sf.net 2005-05-21 13:24:26 MST ----

Created an attachment (id=167996)
Patch




---- Additional Comments From bmaurer@users.sf.net 2005-05-21 13:26:51 MST ----

This patch detects binary files as mentioned above. We now get the
following error:

[benm@linux mcs]$ mono mcs2.exe mcs2.exe
error CS2015: Source file 'mcs2.exe' is a binary file.
Compilation failed: 1 error(s), 0 warnings

Rather than

[benm@linux mcs]$ mcs mcs2.exe
syntax error, got token `ERROR'
mcs2.exe(1) error CS8025: Parsing error
Compilation failed: 1 error(s), 0 warnings

MCS is able to bootstrap -- this tests the case of a file > 4 kb, and
a file smaller (which is why I need to do the int n = stuff on the
stream).



---- Additional Comments From miguel@ximian.com 2005-06-08 14:48:05 MST ----

I actually have a better idea than this.

We could basically detect the zero in the tokenizer



---- Additional Comments From bmaurer@users.sf.net 2005-06-14 00:24:54 MST ----

That assumes that by the time the \0 was noticed, the compiler hadn't
already errored out in a strage way.



---- Additional Comments From bmaurer@users.sf.net 2005-06-14 00:26:51 MST ----

btw, if you are worried about performance, this does *not* cause an
extra syscall. 4kb is less than the default buffer size for
filestream, and thus 8 kb of data will be read into an array.
Position=0 won't discard the contents of the array.

Given the extremely high chances that a binary file will be caught by
this patch, I don't think it worth arguing that we are being more
precise the other way.



---- Additional Comments From miguel@ximian.com 2005-10-01 02:54:13 MST ----

There is a different hack in place now.

Not ideal, but am ok with it.

Imported an attachment (id=167996)

Unknown operating system unknown. Setting to default OS "Other".