Work around the case where hisory buffer is larger than HIS_BUF_LEN (128K).

Ticket: #4736