This is alternative solution for D25279.
Initial problem was that because of overflow in calculations wierd thinks could happen.
Most heavy is a crash in writeTo because of overflow in FileSize calculation.
This patch does not introduce new class and uses 2 check-methods.