static int _TIFFReserveLargeEnoughWriteBuffer(TIFF* tif, uint32 strip_or_tile)
{
    TIFFDirectory *td = &tif->tif_dir;
    if( td->td_stripbytecount[strip_or_tile] > 0 )
    {
        /* The +1 is to ensure at least one extra bytes */
        /* The +4 is because the LZW encoder flushes 4 bytes before the limit */
        uint64 safe_buffer_size = (uint64)(td->td_stripbytecount[strip_or_tile] + 1 + 4);
        if( tif->tif_rawdatasize <= (tmsize_t)safe_buffer_size )
        {
            if( !(TIFFWriteBufferSetup(tif, NULL,
                (tmsize_t)TIFFroundup_64(safe_buffer_size, 1024))) )
                return 0;
        }

        /* Force TIFFAppendToStrip() to consider placing data at end
            of file. */
        tif->tif_curoff = 0;
    }
    return 1;
}