/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 6541476 6782079
* @summary Write and read a PNG file including an non-latin1 iTXt chunk
* Test also verifies that trunkated png images does not cause
* an OoutOfMemory error.
*
* @run main ItxtUtf8Test
*
*/
public class ItxtUtf8Test {
public static final String
"\ud835\udc13\ud835\udc1e\ud835\udc31\ud835\udc2d" +
"\u24c9\u24d4\u24e7\u24e3", // a repetition for compression
public static final byte[]
VBYTES = {
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x56, // chunk length
(byte)0x69, (byte)0x54, (byte)0x58, (byte)0x74, // chunk type "iTXt"
(byte)0x76, (byte)0x65, (byte)0x72, (byte)0x62,
(byte)0x61, (byte)0x74, (byte)0x69, (byte)0x6d, // keyword "verbatim"
(byte)0x00, // separator terminating keyword
(byte)0x00, // compression flag
(byte)0x00, // compression method, must be zero
(byte)0x78, (byte)0x2d, (byte)0x63, (byte)0x69,
(byte)0x72, (byte)0x63, (byte)0x6c, (byte)0x65,
(byte)0x64, // language tag "x-circled"
(byte)0x00, // separator terminating language tag
(byte)0xe2, (byte)0x93, (byte)0xa5, // '\u24e5'
(byte)0xe2, (byte)0x93, (byte)0x94, // '\u24d4'
(byte)0xe2, (byte)0x93, (byte)0xa1, // '\u24e1'
(byte)0xe2, (byte)0x93, (byte)0x91, // '\u24d1'
(byte)0xe2, (byte)0x93, (byte)0x90, // '\u24d0'
(byte)0xe2, (byte)0x93, (byte)0xa3, // '\u24e3'
(byte)0xe2, (byte)0x93, (byte)0x98, // '\u24d8'
(byte)0xe2, (byte)0x93, (byte)0x9c, // '\u24dc'
(byte)0x00, // separator terminating the translated keyword
(byte)0xe2, (byte)0x93, (byte)0x89, // '\u24c9'
(byte)0xe2, (byte)0x93, (byte)0x94, // '\u24d4'
(byte)0xe2, (byte)0x93, (byte)0xa7, // '\u24e7'
(byte)0xe2, (byte)0x93, (byte)0xa3, // '\u24e3'
(byte)0xf0, (byte)0x9d, (byte)0x90, (byte)0x93, // '\ud835\udc13'
(byte)0xf0, (byte)0x9d, (byte)0x90, (byte)0x9e, // '\ud835\udc1e'
(byte)0xf0, (byte)0x9d, (byte)0x90, (byte)0xb1, // '\ud835\udc31'
(byte)0xf0, (byte)0x9d, (byte)0x90, (byte)0xad, // '\ud835\udc2d'
(byte)0xe2, (byte)0x93, (byte)0x89, // '\u24c9'
(byte)0xe2, (byte)0x93, (byte)0x94, // '\u24d4'
(byte)0xe2, (byte)0x93, (byte)0xa7, // '\u24e7'
(byte)0xe2, (byte)0x93, (byte)0xa3, // '\u24e3'
(byte)0xb5, (byte)0xcc, (byte)0x97, (byte)0x56 // CRC
},
CBYTES = {
// we don't want to check the chunk length,
// as this might depend on implementation.
(byte)0x69, (byte)0x54, (byte)0x58, (byte)0x74, // chunk type "iTXt"
(byte)0x63, (byte)0x6f, (byte)0x6d, (byte)0x70,
(byte)0x72, (byte)0x65, (byte)0x73, (byte)0x73,
(byte)0x65, (byte)0x64, // keyword "compressed"
(byte)0x00, // separator terminating keyword
(byte)0x01, // compression flag
(byte)0x00, // compression method, 0=deflate
(byte)0x78, (byte)0x2d, (byte)0x63, (byte)0x69,
(byte)0x72, (byte)0x63, (byte)0x6c, (byte)0x65,
(byte)0x64, // language tag "x-circled"
(byte)0x00, // separator terminating language tag
// we don't want to check the actual compressed data,
// as this might depend on implementation.
};
/*
*/
try {
runTest(false, true);
throw new AssertionError("Expect an error for truncated file");
}
catch (IIOException e) {
// expected an error for a truncated image file.
}
}
else {
}
}
throws Exception
{
if (dump)
throw new AssertionError("verbatim block not found");
throw new AssertionError("compressed block not found");
if (truncate)
boolean verbatimSeen = false, compressedSeen = false;
verbatimSeen = true;
throw new AssertionError("Wrong translated keyword");
throw new AssertionError("Wrong text");
}
compressedSeen = true;
throw new AssertionError("Wrong translated keyword");
throw new AssertionError("Wrong text");
}
else {
throw new AssertionError("Unexpected keyword");
}
}
if (!(verbatimSeen && compressedSeen))
throw new AssertionError("Missing chunk");
}
continue HAYSTACK;
}
}
return h;
}
return -1;
}
}