Skip to content

Instantly share code, notes, and snippets.

@perillamint
Created June 16, 2015 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perillamint/3a97381a524653d68c23 to your computer and use it in GitHub Desktop.
Save perillamint/3a97381a524653d68c23 to your computer and use it in GitHub Desktop.
Exploit of character breaking bug in https://github.com/EBvi/dev-matrix/blob/master/dev-test.md
// NOTE: This example uses tengwar glyph in Unicode SMP.
// To properly render all glyph, you need font which support
// U+16080-160FF range.
//
// Here is modified FreeMonoTengwar font for that purpose.
// http://galadriel.gentoo.moe/tengwar-SMP/
class smptest
{
public static void main(String args[])
{
// Tengwar in SMP. WARN: TENTATIVELY ALLOCATED CODEPOINT
// This string is 32 * 2 + 1 byte in UTF-16
char[] arr = "𖂑𖃄𖂒𖂄𖃄𖂠π–‚₯𖃄 𖂑𖃄𖂒𖂄𖃄𖂠π–‚₯𖃄".toCharArray();
StringBuffer sb = new StringBuffer();
int size = 0;
for (char c : arr)
{
size += (c > 255) ? 2 : 1; //Is it 2byte?
sb.append(c);
// It will break Tehtar U+160C4
if(size >= 63)
break;
}
System.out.println(sb);
//Output: 𖂑𖃄𖂒𖂄𖃄𖂠π–‚₯𖃄 𖂑𖃄𖂒𖂄𖃄𖂠π–‚₯?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment