FIX: Some Character Encoders Ignore Null Bytes (260823)



The information in this article applies to:

  • Microsoft virtual machine, when used with:
    • the operating system: Microsoft Windows 2000
  • Microsoft Internet Explorer (Programming) 3.0
  • Microsoft Internet Explorer (Programming) 3.01
  • Microsoft Internet Explorer (Programming) 3.02
  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01
  • Microsoft SDK for Java 2.0
  • Microsoft SDK for Java 3.0
  • Microsoft SDK for Java 3.0 Preview 1
  • Microsoft SDK for Java 3.1
  • Microsoft SDK for Java 3.2
  • Microsoft SDK for Java 4.0
  • Microsoft Visual J++ 6.0

This article was previously published under Q260823

SYMPTOMS

When you use certain character encoders that are included with the Microsoft virtual machine (Microsoft VM) for Java, null bytes in data streams are ignored.

CAUSE

This is a code defect in the respective byte-to-char converter classes.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug has been verified to occur in the 2400, 3100, and 3200 series of the Microsoft VM.

This problem was corrected in Windows 2000 Service Pack 1.

MORE INFORMATION

In versions of the Microsoft VM series 3200 and earlier, three encoders mistakenly ignore null bytes ("\0") in data streams. The encodings that ignore null bytes are:
  • Big5
  • GB2312
  • KSC5601

Steps to Reproduce Behavior

  1. Compile and run the sample code that is provided in this section.
  2. Notice the null byte on the end of the array that is used to construct the Java string object. If you are running on a 3200 series Microsoft VM or earlier, the output will indicate a string length of "6" for the three defective encodings and "7" for the other two.
import java.io.UnsupportedEncodingException;
public class EncodingTest2
{
  public static void main (String[] args) throws Exception
  {
    try 
    {
      String[] enc = {"Big5", "GB2312", "KSC5601", "ASCII", "UTF8"};
      byte[] data = {(byte)'s',(byte)'t',(byte)'r',(byte)'i',(byte)'n',(byte)'g',(byte)'\0'};
      
      for (int i = 0; i < enc.length; i++)
      {
        String tmpStr = new String(data, enc[i]);
        System.out.println("Encoding = "+enc[i]);
        System.out.println("\t\t\tString length = "+tmpStr.length());
        System.out.println();
      }
      System.in.read();
    }
    catch (UnsupportedEncodingException ex)
    {
      ex.printStackTrace();
      System.in.read();
    }
  }
}
				

REFERENCES

For additional information about the latest service pack for Windows 2000, click the article number below to view the article in the Microsoft Knowledge Base:

260910 How to Obtain the Latest Windows 2000 Service Pack

For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/14/2006
Keywords:kbBug kbfix kbJavaVM33xxfix kbWin2000sp1Fix KB260823