Groups | Blog | Home
all groups > dotnet xml > september 2004 >

dotnet xml : Working app suddenly breaking. Changes to System.Xml.dll?


Andrew Vardeman
9/27/2004 2:16:37 PM
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,

Zafar Abbas [MSFT]
9/27/2004 6:32:39 PM
This is a problem that was introduced by a bug fix made between version 1.1
and SP1. Affected customers can contact PSS and request a QFE if this
problem severely affects their business cases.

[quoted text, click to view]

Andrew Vardeman
9/28/2004 10:04:38 AM
Thanks for the reply. Fortunately, this program was used for data
collection last year and is now only being used by a few people locally
whose installations we can easily replace with a recompiled version.
I'm interested to know, though, whether my code is "incorrect" or just
"unexpected." Whose code is broken, Microsoft's or mine? Will MS "fix"
the issue in a future .NET release? If not, a warning in the
documentation not to fill bytes past bytesRead would be helpful.

Thanks again,

Andrew

[quoted text, click to view]
CLL
11/17/2004 3:08:01 PM
Hi Zafar -

Would it be possible for you to post the KB article number for this QFE so
that we can request it?



[quoted text, click to view]
AddThis Social Bookmark Button