Correctly calculate escape buffer size

Change-Id: I1d4ceb67bce73e90f88d3dee8ec8e4cb1c014bc2