Merge pull request #572 from fredericBregier/3

3 - fix for issue  #569
This commit is contained in:
Norman Maurer 2012-08-28 09:08:22 -07:00
commit 0522c4ffc4
2 changed files with 48 additions and 60 deletions

View File

@ -135,6 +135,8 @@ final class HttpPostBodyUtil {
int pos; int pos;
int origPos;
int limit; int limit;
ChannelBuffer buffer; ChannelBuffer buffer;
@ -148,7 +150,8 @@ final class HttpPostBodyUtil {
} }
this.buffer = buffer; this.buffer = buffer;
bytes = buffer.array(); bytes = buffer.array();
pos = readerIndex = buffer.arrayOffset() + buffer.readerIndex(); readerIndex = buffer.readerIndex();
origPos = pos = buffer.arrayOffset() + readerIndex;
limit = buffer.arrayOffset() + buffer.writerIndex(); limit = buffer.arrayOffset() + buffer.writerIndex();
} }
@ -159,10 +162,19 @@ final class HttpPostBodyUtil {
*/ */
void setReadPosition(int minus) { void setReadPosition(int minus) {
pos -= minus; pos -= minus;
readerIndex = pos; readerIndex = getReadPosition(pos);
buffer.readerIndex(readerIndex); buffer.readerIndex(readerIndex);
} }
/**
*
* @param index raw index of the array (pos in general)
* @return the value equivalent of raw index to be used in readerIndex(value)
*/
int getReadPosition(int index) {
return index - origPos + readerIndex;
}
void clear() { void clear() {
buffer = null; buffer = null;
bytes = null; bytes = null;

View File

@ -849,13 +849,18 @@ public class HttpPostRequestDecoder {
/** /**
* Skip control Characters * Skip control Characters
* @throws NotEnoughDataDecoderException
*/ */
void skipControlCharacters() { void skipControlCharacters() throws NotEnoughDataDecoderException {
SeekAheadOptimize sao = null; SeekAheadOptimize sao = null;
try { try {
sao = new SeekAheadOptimize(undecodedChunk); sao = new SeekAheadOptimize(undecodedChunk);
} catch (SeekAheadNoBackArrayException e) { } catch (SeekAheadNoBackArrayException e) {
try {
skipControlCharactersStandard(undecodedChunk); skipControlCharactersStandard(undecodedChunk);
} catch (IndexOutOfBoundsException e1) {
throw new NotEnoughDataDecoderException(e1);
}
return; return;
} }
@ -866,13 +871,13 @@ public class HttpPostRequestDecoder {
return; return;
} }
} }
sao.setReadPosition(0); throw new NotEnoughDataDecoderException("Access out of bounds");
} }
static void skipControlCharactersStandard(ChannelBuffer buffer) { void skipControlCharactersStandard() {
for (;;) { for (;;) {
char c = (char) buffer.readUnsignedByte(); char c = (char) undecodedChunk.readUnsignedByte();
if (!Character.isISOControl(c) && !Character.isWhitespace(c)) { if (!Character.isISOControl(c) && !Character.isWhitespace(c)) {
buffer.readerIndex(buffer.readerIndex() - 1); undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
break; break;
} }
} }
@ -892,7 +897,12 @@ public class HttpPostRequestDecoder {
throws ErrorDataDecoderException { throws ErrorDataDecoderException {
// --AaB03x or --AaB03x-- // --AaB03x or --AaB03x--
int readerIndex = undecodedChunk.readerIndex(); int readerIndex = undecodedChunk.readerIndex();
try {
skipControlCharacters(); skipControlCharacters();
} catch (NotEnoughDataDecoderException e1) {
undecodedChunk.readerIndex(readerIndex);
return null;
}
skipOneLine(); skipOneLine();
String newline; String newline;
try { try {
@ -933,9 +943,9 @@ public class HttpPostRequestDecoder {
} }
// read many lines until empty line with newline found! Store all data // read many lines until empty line with newline found! Store all data
while (!skipOneLine()) { while (!skipOneLine()) {
skipControlCharacters();
String newline; String newline;
try { try {
skipControlCharacters();
newline = readLine(); newline = readLine();
} catch (NotEnoughDataDecoderException e) { } catch (NotEnoughDataDecoderException e) {
undecodedChunk.readerIndex(readerIndex); undecodedChunk.readerIndex(readerIndex);
@ -1594,8 +1604,8 @@ public class HttpPostRequestDecoder {
// found the decoder limit // found the decoder limit
boolean newLine = true; boolean newLine = true;
int index = 0; int index = 0;
int lastrealpos = sao.pos;
int lastPosition = undecodedChunk.readerIndex(); int lastPosition = undecodedChunk.readerIndex();
int setReadPosition = -1;
boolean found = false; boolean found = false;
while (sao.pos < sao.limit) { while (sao.pos < sao.limit) {
@ -1606,7 +1616,6 @@ public class HttpPostRequestDecoder {
index ++; index ++;
if (delimiter.length() == index) { if (delimiter.length() == index) {
found = true; found = true;
sao.setReadPosition(0);
break; break;
} }
continue; continue;
@ -1620,23 +1629,16 @@ public class HttpPostRequestDecoder {
if (nextByte == HttpConstants.LF) { if (nextByte == HttpConstants.LF) {
newLine = true; newLine = true;
index = 0; index = 0;
setReadPosition = sao.pos; lastrealpos = sao.pos - 2;
lastPosition = sao.pos - 2;
} }
} else {
// save last valid position
setReadPosition = sao.pos;
lastPosition = sao.pos;
} }
} else if (nextByte == HttpConstants.LF) { } else if (nextByte == HttpConstants.LF) {
newLine = true; newLine = true;
index = 0; index = 0;
setReadPosition = sao.pos; lastrealpos = sao.pos - 1;
lastPosition = sao.pos - 1;
} else { } else {
// save last valid position // save last valid position
setReadPosition = sao.pos; lastrealpos = sao.pos;
lastPosition = sao.pos;
} }
} }
} else { } else {
@ -1647,30 +1649,20 @@ public class HttpPostRequestDecoder {
if (nextByte == HttpConstants.LF) { if (nextByte == HttpConstants.LF) {
newLine = true; newLine = true;
index = 0; index = 0;
setReadPosition = sao.pos; lastrealpos = sao.pos - 2;
lastPosition = sao.pos - 2;
} }
} else {
// save last valid position
setReadPosition = sao.pos;
lastPosition = sao.pos;
} }
} else if (nextByte == HttpConstants.LF) { } else if (nextByte == HttpConstants.LF) {
newLine = true; newLine = true;
index = 0; index = 0;
setReadPosition = sao.pos; lastrealpos = sao.pos - 1;
lastPosition = sao.pos - 1;
} else { } else {
// save last valid position // save last valid position
setReadPosition = sao.pos; lastrealpos = sao.pos;
lastPosition = sao.pos;
} }
} }
} }
if (setReadPosition > 0) { lastPosition = sao.getReadPosition(lastrealpos);
sao.pos = setReadPosition;
sao.setReadPosition(0);
}
ChannelBuffer buffer = undecodedChunk.slice(readerIndex, lastPosition - readerIndex); ChannelBuffer buffer = undecodedChunk.slice(readerIndex, lastPosition - readerIndex);
if (found) { if (found) {
// found so lastPosition is correct and final // found so lastPosition is correct and final
@ -1809,7 +1801,7 @@ public class HttpPostRequestDecoder {
boolean newLine = true; boolean newLine = true;
int index = 0; int index = 0;
int lastPosition = undecodedChunk.readerIndex(); int lastPosition = undecodedChunk.readerIndex();
int setReadPosition = -1; int lastrealpos = sao.pos;
boolean found = false; boolean found = false;
while (sao.pos < sao.limit) { while (sao.pos < sao.limit) {
@ -1820,7 +1812,6 @@ public class HttpPostRequestDecoder {
index ++; index ++;
if (delimiter.length() == index) { if (delimiter.length() == index) {
found = true; found = true;
sao.setReadPosition(0);
break; break;
} }
continue; continue;
@ -1834,21 +1825,15 @@ public class HttpPostRequestDecoder {
if (nextByte == HttpConstants.LF) { if (nextByte == HttpConstants.LF) {
newLine = true; newLine = true;
index = 0; index = 0;
lastPosition = sao.pos - 2; lastrealpos = sao.pos - 2;
setReadPosition = sao.pos;
} }
} else {
lastPosition = sao.pos;
setReadPosition = sao.pos;
} }
} else if (nextByte == HttpConstants.LF) { } else if (nextByte == HttpConstants.LF) {
newLine = true; newLine = true;
index = 0; index = 0;
lastPosition = sao.pos - 1; lastrealpos = sao.pos - 1;
setReadPosition = sao.pos;
} else { } else {
lastPosition = sao.pos; lastrealpos = sao.pos;
setReadPosition = sao.pos;
} }
} }
} else { } else {
@ -1859,28 +1844,19 @@ public class HttpPostRequestDecoder {
if (nextByte == HttpConstants.LF) { if (nextByte == HttpConstants.LF) {
newLine = true; newLine = true;
index = 0; index = 0;
lastPosition = sao.pos - 2; lastrealpos = sao.pos - 2;
setReadPosition = sao.pos;
} }
} else {
lastPosition = sao.pos;
setReadPosition = sao.pos;
} }
} else if (nextByte == HttpConstants.LF) { } else if (nextByte == HttpConstants.LF) {
newLine = true; newLine = true;
index = 0; index = 0;
lastPosition = sao.pos - 1; lastrealpos = sao.pos - 1;
setReadPosition = sao.pos;
} else { } else {
lastPosition = sao.pos; lastrealpos = sao.pos;
setReadPosition = sao.pos;
} }
} }
} }
if (setReadPosition > 0) { lastPosition = sao.getReadPosition(lastrealpos);
sao.pos = setReadPosition;
sao.setReadPosition(0);
}
if (found) { if (found) {
// found so lastPosition is correct // found so lastPosition is correct
// but position is just after the delimiter (either close delimiter or simple one) // but position is just after the delimiter (either close delimiter or simple one)