#86 Error when connecting "hex val 0x00 is an invalid character"

closed-invalid
nobody
None
5
2012-01-25
2012-01-25
Anonymous
No

10.139.23.65

"." hexadecimal value 0x00, is an invalid character. Line 29, position 1

I get this error intermittently with the latest version of dotnetwiki bot (2.98) the error is when creating a new page instance and it attempts to connect. here is my source line:

and the error message:

Error!
"." hexadecimal value 0x00, is an invalid character. Line 29, position 1

Now if I use an incorrect password, or login etc it just fails on incorrect password, but given correct login details it appears to login and then I get a parsing error somewhere in the source. This only happens on a remote machine so I am having trouble getting visual studio on there to debug the issue further. It seems to be fine for months and then randomly it will start happening again. I can manually login create and save mediawiki pages without issue.

The same program works fine on every other mediawiki server, just this one that seems to be having issues. Unfortunately it is on a private network and I am unable to give connection details for testing.

The server which is having issues is set up for replication between 5 nodes, all 5 nodes and the master all give the same error code, then it will seemingly go away for a few months only to return.

If you have any ideas at all as to what could be causing this it would be greatly appreciated. Contact me on here or via roland.c.harrison@gmail.com

Thanks :)

Discussion


  • Anonymous
    2012-01-25

    • priority: 5 --> 9
     

  • Anonymous
    2012-01-25

    Yes, I see the problem. Thanks for reporting it.

     

  • Anonymous
    2012-01-25

    Fixed the problem, for some reason our MediaWiki installation was appending ~200 bytes of nullchars to every response it was sending. This isn't really a dotNetWikiBot bug as such, just that it lacks error handling for this situation. I've hacked in some error handling in my copy, if you feel it is not necessary to handle this obscure error then that is understandable to me. Here is the code I changed:

    Line 488 changed from:
    XmlTextReader reader = new XmlTextReader(new StringReader(src));
    To:
    XmlTextReader reader = new XmlTextReader(new StringReader(RemoveTroublesomeCharacters(new StringReader(src).ReadToEnd())));

    and line 3283 changed from:
    using (XmlTextReader reader = new XmlTextReader(new StringReader(src)))
    to:
    using (XmlTextReader reader = new XmlTextReader(new StringReader(RemoveTroublesomeCharacters(new StringReader(src).ReadToEnd()))))

    and the new function is:
    /// <summary>
    /// Removes control characters and other non-UTF-8 characters
    /// </summary>
    /// <param name="inString">The string to process</param>
    /// <returns>A string with no control characters or entities above 0x00FD</returns>
    /// Added by roland harrison
    public static string RemoveTroublesomeCharacters(string inString)
    {
    if (inString == null) return null;
    StringBuilder newString = new StringBuilder();
    char ch;
    for (int i = 0; i < inString.Length; i++)
    {
    ch = inString[i];
    // remove any characters outside the valid UTF-8 range as well as all control characters
    // except tabs and new lines
    if ((ch < 0x00FD && ch > 0x001F) || ch == '\t' || ch == '\n' || ch == '\r')
    {
    if (ch != 0)
    {
    newString.Append(ch);
    }
    }
    }
    return newString.ToString();
    }

     
  • CodeDriller
    CodeDriller
    2012-01-25

    • priority: 9 --> 5
    • status: open --> closed-invalid
     
  • CodeDriller
    CodeDriller
    2012-01-25

    Let's see. If those ~200 bytes of nullchars are caused by bug in MediaWiki, then the fix must be applied.

    What is the version of your MediaWiki installation and your web server?

    Please, make sure that no characters (visible or invisible) are present after ?> in the ends of MediaWiki's PHP files that you edited manually (LocalSettings.php, etc.).