Both max_filepos and offset are int64_t, so pos can overflow, e.g. causing endless loops in stream implementation.