Reviewed-by: xuelei, valeriep
Detect potential buffer overlap and use extra buffer if necessary Reviewed-by: xuelei