""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see . Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see One-shot upgrade migration: drop any legacy non-JSON scan queue file. The runtime reads JSON only; migration 002 already normalized the on-disk objects to plain dicts. """ import logging from pathlib import Path logger = logging.getLogger(__name__) SCANS_PATH = Path("/var/imunify360/aibolit/scans.pickle") def _looks_like_json(raw: bytes) -> bool: head = raw.lstrip()[:1] return head in (b"[", b"{") def migrate(migrator, *_, fake=False, **__): if fake or not SCANS_PATH.exists(): return if _looks_like_json(SCANS_PATH.read_bytes()): return # Drop, don't pickle-load: deserializing this file is the RCE we remove. logger.warning("Removing legacy non-JSON scans file %s", SCANS_PATH) SCANS_PATH.unlink(missing_ok=True) def rollback(migrator, *_, fake=False, **__): pass