Disallow deep or widely nested entity references.

Nested entities with a depth of 2 or more will fail. Entities
that fully expand to more than 1024 characters will also fail.

Change-Id: I75525bc1edfa796c4db30a5109fe21011ad43a2d
Reviewed-by: Richard J. Moore <rich@kde.org>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
(cherries picked from commits 46a8885ae486e238a39efa5119c2714f328b08e4
and f1053d94f59f053ce4acad9320df14f1fbe4faac)