Hi all.
Recent Windows updates seem to have broken our application. It used to
run fine but now fails with XmlExceptions when loading a document.
We've narrowed the problem to the following:
We create an XmlTextReader by passing an instance of our own subclass of
FileStream. Our subclass is called "ObfuscatingFileStream," and it
overrides the Read and Write methods by shifting bits to discourage our
users from hand-editing our documents. Here are the methods:
//------------------------------------------------------------
public override int Read(byte[] array, int offset, int count){
int bytesRead = base.Read(array, offset, count);
for(int i = 0; i < count; i++){
byte b = array[i];
array[i] = (byte)((b&128)/128 + (b << 1));
}
return bytesRead;
}
public override void Write(byte[] array,int offset,int count){
for(int i = 0; i < count; i++){
byte b = array[i];
array[i] = (byte)(128*(b&1) + (b >> 1));
}
base.Write(array, offset, count);
}
//------------------------------------------------------------
This code worked fine until very recently, when users started to
complain that they could no longer open documents in our app. They get
random XmlExceptions. Uninstalling the .NET Framework and reinstalling
from the .NET developer 1.1 redistributable always fixes the problem...
temporarily. Then in a few days it's broken again. I suspect Windows
Update.
So my supervisor has discovered that replacing "count" in the for loop
of the read method with "bytesRead" fixes our problem.
But why? What recent change has been made to .NET's XML readers that
suddenly makes the *unused* portion of the buffer significant? Why on
earth should it matter whether we change bytes after array[bytesRead]?
Thanks for any help,