Re: [hybi] Framing take IV [why fragment]

Roberto Peon <fenix@google.com> Thu, 05 August 2010 16:48 UTC

Return-Path: <fenix@google.com>
X-Original-To: hybi@core3.amsl.com
Delivered-To: hybi@core3.amsl.com
Received: from localhost (localhost [127.0.0.1]) by core3.amsl.com (Postfix) with ESMTP id 53D663A6857 for <hybi@core3.amsl.com>; Thu, 5 Aug 2010 09:48:03 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -105.67
X-Spam-Level:
X-Spam-Status: No, score=-105.67 tagged_above=-999 required=5 tests=[AWL=0.306, BAYES_00=-2.599, FM_FORGED_GMAIL=0.622, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_MED=-4, USER_IN_WHITELIST=-100]
Received: from mail.ietf.org ([64.170.98.32]) by localhost (core3.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Iq8uOaFoKtDd for <hybi@core3.amsl.com>; Thu, 5 Aug 2010 09:48:00 -0700 (PDT)
Received: from smtp-out.google.com (smtp-out.google.com [216.239.44.51]) by core3.amsl.com (Postfix) with ESMTP id 363853A6B37 for <hybi@ietf.org>; Thu, 5 Aug 2010 09:47:27 -0700 (PDT)
Received: from kpbe19.cbf.corp.google.com (kpbe19.cbf.corp.google.com [172.25.105.83]) by smtp-out.google.com with ESMTP id o75GltXq011447 for <hybi@ietf.org>; Thu, 5 Aug 2010 09:47:55 -0700
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1281026875; bh=ZnqirUpMju0s+BUgz6u8bwjZUUU=; h=MIME-Version:In-Reply-To:References:Date:Message-ID:Subject:From: To:Cc:Content-Type; b=q33fFVIce0MH98Pz/JdvvqZXsaVUftAAt0ua8WB/4wWxGQWrOqjEaXm5GioZguc4T tuIe6D+xoazqkNeKhWvwQ==
DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=mime-version:in-reply-to:references:date:message-id:subject:from:to: cc:content-type:x-system-of-record; b=rF40EQvg7Q2HVBgGLcFt0ABA+AGXEhQExb0I31s/+M5D97htpzX5QTrxBIDSLikGS /cGGimIkoihr6umbQDKsA==
Received: from gxk27 (gxk27.prod.google.com [10.202.11.27]) by kpbe19.cbf.corp.google.com with ESMTP id o75GlLXd008247 for <hybi@ietf.org>; Thu, 5 Aug 2010 09:47:41 -0700
Received: by gxk27 with SMTP id 27so3152096gxk.36 for <hybi@ietf.org>; Thu, 05 Aug 2010 09:47:41 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.151.62.5 with SMTP id p5mr12645868ybk.55.1281026861325; Thu, 05 Aug 2010 09:47:41 -0700 (PDT)
Received: by 10.150.59.4 with HTTP; Thu, 5 Aug 2010 09:47:41 -0700 (PDT)
In-Reply-To: <Pine.LNX.4.64.1008041956161.5947@ps20323.dreamhostps.com>
References: <AANLkTinyrDoG5d_Ur6HVRy=SgMPjLzJtpJ++Ye=1DQdj@mail.gmail.com> <Pine.LNX.4.64.1008040050040.5947@ps20323.dreamhostps.com> <AANLkTi=3CJDKu37LV+6CG=d7VP5fOe-JNV9Cd=99BjjA@mail.gmail.com> <2AD09E86-CFFE-4378-A437-7EAE2E3026FD@apple.com> <1280937841.7561.292.camel@tng> <Pine.LNX.4.64.1008041754000.5947@ps20323.dreamhostps.com> <1280947861.7561.388.camel@tng> <Pine.LNX.4.64.1008041956161.5947@ps20323.dreamhostps.com>
Date: Thu, 05 Aug 2010 09:47:41 -0700
Message-ID: <AANLkTim6Do+P4sCXsR+sJ6R_ZYQKQYvpakPdKV9aNv6b@mail.gmail.com>
From: Roberto Peon <fenix@google.com>
To: Ian Hickson <ian@hixie.ch>
Content-Type: multipart/alternative; boundary="000e0cd59250045daa048d164f03"
X-System-Of-Record: true
Cc: hybi@ietf.org
Subject: Re: [hybi] Framing take IV [why fragment]
X-BeenThere: hybi@ietf.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: Server-Initiated HTTP <hybi.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/hybi>
List-Post: <mailto:hybi@ietf.org>
List-Help: <mailto:hybi-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 05 Aug 2010 16:48:03 -0000

The biggest reason that variable length encoding is annoying is that it
either adds complexity of buffer management or it adds overhead dealing with
the system.

A big advantage of length-prefixed data is that one need only read the
length, and then one can do a single alloc and read() to consume the rest of
the message exactly.

If any part of this is sentinel based (and that is what BER is,
effectively), you end up either doing read() one byte at a time, or you end
up doing a read for something you're guessing is larger than the max length.
If you guess wrong, you either have to have kept the encoded state from the
previous read, read more (involves another alloc), and only then do you get
to alloc and read the payload.

If you've guessed wrong and you read too much, then you have to save that
data, alloc another buffer, move it, and only then can you safely delete the
previous buffer.

This is a fair bit of complexity.
What is the gain?
-=R

On Wed, Aug 4, 2010 at 12:58 PM, Ian Hickson <ian@hixie.ch> wrote:

> On Wed, 4 Aug 2010, Patrick McManus wrote:
> > On Wed, 2010-08-04 at 17:55 +0000, Ian Hickson wrote:
> > > On Wed, 4 Aug 2010, Patrick McManus wrote:
> > > >
> > > > But I also believe fragments with fixed lengths are simpler than a
> > > > BER because properly aligned lengths are always correct data - there
> > > > are no error cases as all the bits are defined to be some quantity
> > > > regardless of their arrangement. BER has error cases and determining
> > > > the expressed quantity requires multiple indirections and a
> > > > significant algorithm to use it.
> > >
> > > As far as I can tell there are no error cases as defined in
> > > WebSockets.
> >
> > I believe the specific ber length suggestion was:
> >
> >  - a BER-encoded packed integer, most-significant-digits first, high bit
> > used to indicate a continuation byte, giving the payload length.
> >
> > In that case, as I understand it, it would be an error if the ber type
> > encoding byte didn't specify a universal primitive type of 2. (or maybe
> > I'm wrong and it needs to be some other identifier - but that doesn't
> > really matter).
> >
> > it is not a big deal, but it is an error case.
>
> The spec just uses the packed integer part, not the whole ASN.1 form.
> There are no error conditions with that as far as I can tell. There's one
> redundancy (leading 0x80 bytes), but that's not an error case, and since
> the behaviour is well-defined, doesn't even seen to be a likely attack
> vector (which redundancies can often become), though naturally we'd want
> to make sure we tested that thoroughly in our test suite.
>
> --
> Ian Hickson               U+1047E                )\._.,--....,'``.    fL
> http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
> Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
> _______________________________________________
> hybi mailing list
> hybi@ietf.org
> https://www.ietf.org/mailman/listinfo/hybi
>