1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-15 14:05:05 -05:00

Some fixes to WBXML. Turns out recursing through the folder listing can overflow the stack, so loop over it instead.

This commit is contained in:
Matthew Brace 2009-03-14 02:43:53 +00:00
parent e6b323ae27
commit 5a729ab0df

View File

@ -113,14 +113,12 @@ class WBXML {
BufferedOutputStream ostream, BufferedOutputStream ostream,
CodePage codepage) throws IOException { CodePage codepage) throws IOException {
int streamByte = istream.read(); int streamByte = istream.read();
while (streamByte != -1) {
int attribute = 0; int attribute = 0;
String currentNamespace = codepage.getCodePageName(); String currentNamespace = codepage.getCodePageName();
String outputBuffer = new String(); String outputBuffer = new String();
if (streamByte == -1) {
return;
}
/* Process WBXML tokens */ /* Process WBXML tokens */
if ((streamByte & 15) <= 0x4 && ((streamByte >>> 4) % 4) == 0) { if ((streamByte & 15) <= 0x4 && ((streamByte >>> 4) % 4) == 0) {
/* Can't switch on a string, so switch on the raw value */ /* Can't switch on a string, so switch on the raw value */
@ -193,7 +191,6 @@ class WBXML {
/* Write the data we have to the output buffer */ /* Write the data we have to the output buffer */
outputBuffer = new String("BASE64"); outputBuffer = new String("BASE64");
outputBuffer = outputBuffer + Utility.base64Encode(new String(data)); outputBuffer = outputBuffer + Utility.base64Encode(new String(data));
//outputBuffer = new String(data, "UTF-8");
break; break;
case 0xc4: /* literal_ac */ case 0xc4: /* literal_ac */
break; break;
@ -231,14 +228,17 @@ class WBXML {
} }
} }
if (outputBuffer.length() > 0) {
ostream.write(outputBuffer.getBytes(), 0, outputBuffer.length()); ostream.write(outputBuffer.getBytes(), 0, outputBuffer.length());
ostream.flush(); ostream.flush();
}
if (attribute > 0) { if (attribute > 0) {
processAttributeState(istream, ostream, codepage); processAttributeState(istream, ostream, codepage);
} }
processTagState(istream, ostream, codepage); streamByte = istream.read();
}
} }
private void processAttributeState(BufferedInputStream istream, private void processAttributeState(BufferedInputStream istream,
@ -323,7 +323,6 @@ class WBXML {
/* Write the data we have to the output buffer */ /* Write the data we have to the output buffer */
outputBuffer = new String("BASE64"); outputBuffer = new String("BASE64");
outputBuffer = outputBuffer + Utility.base64Encode(new String(data)); outputBuffer = outputBuffer + Utility.base64Encode(new String(data));
//outputBuffer = new String(data, "UTF-8");
break; break;
case 0xc4: /* literal_ac */ case 0xc4: /* literal_ac */
break; break;
@ -474,13 +473,13 @@ class WBXML {
* the codepages. * the codepages.
*/ */
if (!codepage.getCodePageName().equals(namespaceURI)) { if (!codepage.getCodePageName().equals(namespaceURI)) {
for (int i = 0, count = pageList.length - 1; i < count; i++) { for (int i = 0, count = pageList.length; i < count; i++) {
if (pageList[i].getCodePageName().equals(namespaceURI)) { if (pageList[i].getCodePageName().equals(namespaceURI)) {
codepage = pageList[i]; codepage = pageList[i];
/* Write the code page change to the stream */ /* Write the code page change to the stream */
try { try {
ostream.write(0x00); ostream.write(0x00);
ostream.write(i); ostream.write(codepage.getCodePageIndex());
} catch (IOException ioe) { } catch (IOException ioe) {
throw new SAXException("IOException writing page change: " + ioe); throw new SAXException("IOException writing page change: " + ioe);
} }
@ -553,7 +552,12 @@ class WBXML {
@Override @Override
public void characters(char ch[], int start, int length) { public void characters(char ch[], int start, int length) {
String hexString = new String(ch, start, 6); String hexString = new String();
if (length > 6) {
hexString = new String(ch, start, 6);
}
/* Fix up the tag in the pending buffer if necessary */ /* Fix up the tag in the pending buffer if necessary */
if (pendingBuffer.size() > 0) { if (pendingBuffer.size() > 0) {
int tagByte = pendingBuffer.get(0); int tagByte = pendingBuffer.get(0);