fix possible copy of null buffer and validation of unitialized header