Bug 1192 - Searching in binary files does not work
Summary: Searching in binary files does not work
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: General ()
Version: Trunk
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Alan McGovern
URL:
Depends on:
Blocks:
 
Reported: 2011-10-03 09:35 UTC by Alan McGovern
Modified: 2011-10-25 12:01 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Alan McGovern 2011-10-03 09:35:53 UTC
it's impossible to search for the string "true" (including the quote marks) inside MonoDevelop as it throws an exception.
Comment 1 Alan McGovern 2011-10-03 09:48:57 UTC
I have 'include binary files' enabled which is causing this error to happen as MD opens *every* file as if it were valid UTF8. To be honest, this behaviour is broken. Binary files need to be opened as binary. We might be able to work around it by using a non-throwing version of UTF8Encoding when creating the StreamReader, but this particular bug may still happen as the exception happens before the converter tries converting the bytes to actual characters.
Comment 2 Alan McGovern 2011-10-03 09:58:24 UTC
Exception trace:


System.ArgumentException: Arg_InsufficientSpace
Parameter name: chars
  at System.Text.UTF8Encoding.InternalGetChars (System.Byte* bytes, Int32 byteCount, System.Char* chars, Int32 charCount, System.UInt32& leftOverBits, System.UInt32& leftOverCount, System.Object provider, System.Text.DecoderFallbackBuffer& fallbackBuffer, System.Byte[]& bufferArg, Boolean flush) [0x00000] in <filename unknown>:0 
  at System.Text.UTF8Encoding.InternalGetChars (System.Byte[] bytes, Int32 byteIndex, Int32 byteCount, System.Char[] chars, Int32 charIndex, System.UInt32& leftOverBits, System.UInt32& leftOverCount, System.Object provider, System.Text.DecoderFallbackBuffer& fallbackBuffer, System.Byte[]& bufferArg, Boolean flush) [0x00000] in <filename unknown>:0 
  at System.Text.UTF8Encoding+UTF8Decoder.GetChars (System.Byte[] bytes, Int32 byteIndex, Int32 byteCount, System.Char[] chars, Int32 charIndex) [0x00000] in <filename unknown>:0 
  at System.IO.StreamReader.ReadBuffer () [0x00000] in <filename unknown>:0 
  at System.IO.StreamReader.Read (System.Char[] buffer, Int32 index, Int32 count) [0x00000] in <filename unknown>:0 
  at System.IO.StreamReader.ReadToEnd () [0x00000] in <filename unknown>:0 
  at MonoDevelop.Ide.FindInFiles.FileProvider.BeginReplace () [0x00015] in /Users/alanmcgovern/Projects/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/FileProvider.cs:114 
  at MonoDevelop.Ide.FindInFiles.FindReplace+<FindAll>c__IteratorA.MoveNext () [0x0016e] in /Users/alanmcgovern/Projects/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/FindReplace.cs:94 
  at MonoDevelop.Ide.FindInFiles.FindInFilesDialog.SearchReplace (System.String replacePattern) [0x001d0] in /Users/alanmcgovern/Projects/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/FindInFilesDialog.cs:567
Comment 3 Alan McGovern 2011-10-03 10:03:55 UTC
2 issues:

1) How should we search binary files
2) How should we handle text files which throw an exception when reading them during search. Skip them or abort the search?
Comment 4 Mikayla Hutchinson [MSFT] 2011-10-03 10:05:08 UTC
Not sure why we're reading entire files into memory instead of streaming. Do we have some cap of the size of files we read?

We should use MD's TextFile API to autodetect the encoding.
Comment 5 Alan McGovern 2011-10-03 10:18:17 UTC
Detecting the encoding using the TextFile API would be great for text files, but we still shouldn't really be opening binary files as any kind of text as we're going to hit the issue as described above. Maybe this is a bug in  UTF8Encoding.InternalGetChars and this crash shouldn't happen, but currently it does break binary file searching within MD.
Comment 6 Alan McGovern 2011-10-25 12:01:05 UTC
This has been fixed already