Bug 723448: abcdump: undo in readUTFBytes leading UTF BOM compensation (r=edwsmith).
authorFelix S Klock II <fklockii@adobe.com>
Thu, 09 Feb 2012 13:45:07 +0100
changeset 7193 99987b9691556cc647756c0f994c485051e3daaa
parent 7192 d0f8ed436179d26dda0576c513470727a5bcd789
child 7194 295ea0db9331932532561b4b1429a97a5ed53910
push id4135
push userfklockii@adobe.com
push dateThu, 09 Feb 2012 12:45:28 +0000
reviewersedwsmith
bugs723448
Bug 723448: abcdump: undo in readUTFBytes leading UTF BOM compensation (r=edwsmith).
utils/abcdump.as
--- a/utils/abcdump.as
+++ b/utils/abcdump.as
@@ -942,18 +942,38 @@ package abcdump
 
                infoPrint("Cpool float4s size "+(data.position-start)+" "+int(100*(data.position-start)/data.length)+" %")
                start = data.position
             }
 
             // strings
             n = readU32()
             strings = [""]
-            for (i=1; i < n; i++)
-                strings[i] = data.readUTFBytes(readU32())
+            for (i=1; i < n; i++) {
+                var len = readU32();
+                var posPreRead = data.position;
+                strings[i] = data.readUTFBytes(len);
+                // Bugzilla 723448: ByteArray.readUTFBytes deliberately
+                // skips an initial UTF8 BOM in the input.  Compensate
+                // for this here.
+                if (len >= 3 && (data[posPreRead+0] == 0xEF &&
+                                 data[posPreRead+1] == 0xBB &&
+                                 data[posPreRead+2] == 0xBF)) {
+                    // First, double-check that readUTFBytes is still
+                    // compensating for UTF8 BOM.  (Presumed rare and
+                    // thus not worth caching or precomputing.)
+                    var tempByteArray = new ByteArray();
+                    tempByteArray.writeUTFBytes('\ufeff');
+                    tempByteArray.position = 0;
+                    var s = tempByteArray.readUTFBytes(tempByteArray.length);
+                    if (s == "") {
+                        strings[i] = '\ufeff'+strings[i];
+                    }
+                }
+            }
             dumpPool("string", strings)
 
             infoPrint("Cpool strings count "+ n +" size "+(data.position-start)+" "+int(100*(data.position-start)/data.length)+" %")
             start = data.position
 
             // namespaces
             n = readU32()
             namespaces = [publicNs]