private static int toFrameLength(long l) throws TooLongFrameException { if (l > Integer.MAX_VALUE) { throw new TooLongFrameException("Length:" + l); } else { return (int) l; } }
private void fail(final ChannelHandlerContext ctx, String length) { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException( "frame length (" + length + ") exceeds the allowed maximum (" + maxLength + ')')); }
private void fail(ChannelHandlerContext ctx, long frameLength) { if (frameLength > 0) { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException( "frame length exceeds " + maxFrameLength + ": " + frameLength + " - discarded")); } else { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException( "frame length exceeds " + maxFrameLength + " - discarding")); } }
private static String readLine(ChannelBuffer buffer, int maxLineLength) throws TooLongFrameException { StringBuilder sb = new StringBuilder(64); int lineLength = 0; while (true) { byte nextByte = buffer.readByte(); if (nextByte == HttpConstants.CR) { nextByte = buffer.readByte(); if (nextByte == HttpConstants.LF) { return sb.toString(); } } else if (nextByte == HttpConstants.LF) { return sb.toString(); } else { if (lineLength >= maxLineLength) { // TODO: Respond with Bad Request and discard the traffic // or close the connection. // No need to notify the upstream handlers - just log. // If decoding a response, just throw an exception. throw new TooLongFrameException( "An HTTP line is larger than " + maxLineLength + " bytes."); } lineLength ++; sb.append((char) nextByte); } } }
throw new TooLongFrameException( "HTTP header is larger than " + maxHeaderSize + " bytes.");
private void fail(ChannelHandlerContext ctx, long frameLength) { if (frameLength > 0) { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException( "Adjusted frame length exceeds " + maxFrameLength + ": " + frameLength + " - discarded")); } else { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException( "Adjusted frame length exceeds " + maxFrameLength + " - discarding")); } } }
private WebSocketFrame decodeBinaryFrame(byte type, ChannelBuffer buffer) throws TooLongFrameException { long frameSize = 0; int lengthFieldSize = 0; byte b; do { b = buffer.readByte(); frameSize <<= 7; frameSize |= b & 0x7f; if (frameSize > maxFrameSize) { throw new TooLongFrameException(); } lengthFieldSize++; if (lengthFieldSize > 8) { // Perhaps a malicious peer? throw new TooLongFrameException(); } } while ((b & 0x80) == 0x80); if (type == (byte) 0xFF && frameSize == 0) { receivedClosingHandshake = true; return new CloseWebSocketFrame(); } return new BinaryWebSocketFrame(buffer.readBytes((int) frameSize)); }
throw new TooLongFrameException(); } else { throw new TooLongFrameException();
private int toFrameLength(long l) throws TooLongFrameException { if (l > Integer.MAX_VALUE) { throw new TooLongFrameException("Length:" + l); } else { return (int) l; } } }
throw new TooLongFrameException("invalid payload for PING (payload length must be <= 125, was " + length);
tooLongFrameFound = true; throw new TooLongFrameException( "HTTP content length exceeded " + maxContentLength + " bytes.");
@Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) throws Exception { if (discardingTooLongFrame) { buffer.skipBytes(actualReadableBytes()); checkpoint(); return null; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(buffer); if (maxObjectSize != Integer.MAX_VALUE) { input = new LimitingByteInput(input, maxObjectSize); } try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); return obj; } catch (LimitingByteInput.TooBigObjectException e) { discardingTooLongFrame = true; throw new TooLongFrameException(); } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
if (content.readableBytes() > maxFrameSize - msg.getBinaryData().readableBytes()) { tooLongFrameFound = true; throw new TooLongFrameException( "WebSocketFrame length exceeded " + content + " bytes.");
private int toFrameLength(long l) throws TooLongFrameException { if (l > Integer.MAX_VALUE) { throw new TooLongFrameException("Length:" + l); } else { return (int) l; } } }
if (content.readableBytes() > maxContentLength - spdyDataFrame.getData().readableBytes()) { removeMessage(streamId); throw new TooLongFrameException( "HTTP content length exceeded " + maxContentLength + " bytes.");
throw new TooLongFrameException("invalid payload for PING (payload length must be <= 125, was " + length);
private void fail(final ChannelHandlerContext ctx, String length) { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException( "frame length (" + length + ") exceeds the allowed maximum (" + maxLength + ')')); }
private void throwTooLongFrameException(ChannelHandlerContext ctx) { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException("message size exceeds " + maxMessageSize)); }
private void fail(ChannelHandlerContext ctx, long frameLength) { if (frameLength > 0) { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException( "frame length exceeds " + maxFrameLength + ": " + frameLength + " - discarded")); } else { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException( "frame length exceeds " + maxFrameLength + " - discarding")); } }
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { try { boolean continueProcessing = TcpTransport.validateMessageHeader(Netty3Utils.toBytesReference(buffer)); buffer.skipBytes(TcpHeader.MARKER_BYTES_SIZE + TcpHeader.MESSAGE_LENGTH_SIZE); return continueProcessing ? buffer : null; } catch (IllegalArgumentException ex) { throw new TooLongFrameException(ex.getMessage(), ex); } catch (IllegalStateException ex) { return null; } }