[PDF] Fix name objects containing characters > 0x80 and add a test.
authorvandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 5 Mar 2012 18:44:33 +0000 (18:44 +0000)
committervandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 5 Mar 2012 18:44:33 +0000 (18:44 +0000)
This fixes chrome bug http://crbug.com/115258

Review URL: https://codereview.appspot.com/5726048

git-svn-id: http://skia.googlecode.com/svn/trunk@3319 2bbb7eff-a529-9590-31e7-b0007b416f81

src/pdf/SkPDFTypes.cpp
tests/PDFPrimitivesTest.cpp

index f97f21b..5a0ede8 100644 (file)
@@ -297,7 +297,8 @@ SkString SkPDFName::FormatName(const SkString& input) {
     for (size_t i = 0; i < input.size(); i++) {
         if (input[i] & 0x80 || input[i] < '!' || input[i] == '#') {
             result.append("#");
-            result.appendHex(input[i], 2);
+            // Mask with 0xFF to avoid sign extension. i.e. #FFFFFF81
+            result.appendHex(input[i] & 0xFF, 2);
         } else {
             result.append(input.c_str() + i, 1);
         }
index 82686ef..1aed3ad 100644 (file)
@@ -275,6 +275,14 @@ static void TestPDFPrimitives(skiatest::Reporter* reporter) {
     CheckObjectOutput(reporter, name.get(), expectedResult,
                       strlen(expectedResult), false, false);
 
+    // Test that we correctly handle characters with the high-bit set.
+    char highBitCString[] = {0xDE, 0xAD, 'b', 'e', 0xEF, 0};
+    SkRefPtr<SkPDFName> highBitName = new SkPDFName(highBitCString);
+    name->unref();  // SkRefPtr and new both took a reference.
+    const char highBitExpectedResult[] = "/#DE#ADbe#EF";
+    CheckObjectOutput(reporter, highBitName.get(), highBitExpectedResult,
+                      strlen(highBitExpectedResult), false, false);
+
     SkRefPtr<SkPDFArray> array = new SkPDFArray;
     array->unref();  // SkRefPtr and new both took a reference.
     SimpleCheckObjectOutput(reporter, array.get(), "[]");