Encode headers crash

Fix buffer overrun when encoding headers that are excessively large. Report error back up stack.