|
| 1 | +# SPDX-FileCopyrightText: The LineageOS Project |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import sys |
| 5 | +from fnmatch import fnmatch |
| 6 | +from pathlib import Path |
| 7 | +from typing import Callable, List |
| 8 | + |
| 9 | +from extract_utils.utils import Color, color_print |
| 10 | + |
| 11 | +""" |
| 12 | +Prohibited blob policy |
| 13 | +
|
| 14 | +This module blocks extraction of prohibited files including: |
| 15 | +
|
| 16 | + - Megvii / Face++ (face recognition, beautification, etc.) |
| 17 | + - SenseTime license files (e.g. license.lic) |
| 18 | +
|
| 19 | +These are disallowed due to licensing, redistribution restrictions, |
| 20 | +and more importantly DMCA takedown risk. |
| 21 | +
|
| 22 | +To extend this policy: |
| 23 | + - Add fnmatch pattern + checker function pairs to PROHIBITED_CHECKS |
| 24 | +""" |
| 25 | + |
| 26 | + |
| 27 | +def _check_sensetime(data: bytes) -> bool: |
| 28 | + return any(x in data for x in [b'com.sensetime', b'SenseTime']) |
| 29 | + |
| 30 | + |
| 31 | +def _check_megvii(data: bytes) -> bool: |
| 32 | + return any(x in data for x in [b'megface', b'megvii', b'MEGVII']) |
| 33 | + |
| 34 | + |
| 35 | +# Maps fnmatch pattern (matched against lowercase basename) to a binary |
| 36 | +# checker function. The file is only read if the filename matches. |
| 37 | +PROHIBITED_CHECKS: List[tuple[str, str, Callable[[bytes], bool]]] = [ |
| 38 | + ('*.lic', 'SenseTime', _check_sensetime), |
| 39 | + ('libmegface*', 'Megvii/Face++', _check_megvii), |
| 40 | + ('libmegjpeg*', 'Megvii/Face++', _check_megvii), |
| 41 | + ('libmegskeleton*', 'Megvii/Face++', _check_megvii), |
| 42 | + ('libmegvii*', 'Megvii/Face++', _check_megvii), |
| 43 | + ('libmgbeauty*', 'Megvii/Face++', _check_megvii), |
| 44 | + ('libmgface*', 'Megvii/Face++', _check_megvii), |
| 45 | +] |
| 46 | + |
| 47 | + |
| 48 | +def check_prohibited_file(dst: str, file_path: str): |
| 49 | + basename = Path(dst).name.lower() |
| 50 | + |
| 51 | + for pattern, label, checker in PROHIBITED_CHECKS: |
| 52 | + if not fnmatch(basename, pattern): |
| 53 | + continue |
| 54 | + try: |
| 55 | + data = open(file_path, 'rb').read(4 * 1024 * 1024) |
| 56 | + except OSError: |
| 57 | + continue |
| 58 | + if not checker(data): |
| 59 | + continue |
| 60 | + |
| 61 | + color_print( |
| 62 | + f'ERROR: Prohibited file detected: {dst}', |
| 63 | + color=Color.RED, |
| 64 | + ) |
| 65 | + color_print( |
| 66 | + f' Reason: {label} binary signature matched in {Path(dst).name}', |
| 67 | + color=Color.RED, |
| 68 | + ) |
| 69 | + print() |
| 70 | + color_print('Policy violation:', color=Color.RED) |
| 71 | + print( |
| 72 | + """The following categories of files are not allowed: |
| 73 | +
|
| 74 | + - Megvii / Face++ related libraries and assets: |
| 75 | + (e.g. lib*{M,m}eg*.so, lib*{M,m}g*.so, *{M,m}egvii*) |
| 76 | +
|
| 77 | + - SenseTime license artifacts: |
| 78 | + (e.g. license.lic) |
| 79 | +
|
| 80 | +These files are not permitted in LineageOS repositories/builds. |
| 81 | +
|
| 82 | +Please look for available shims, or develop one to mitigate these dependencies. |
| 83 | +
|
| 84 | +To extract them anyway for a private/local build, re-run with: |
| 85 | +
|
| 86 | +extract-files.py --allow-prohibited-files [...] |
| 87 | +""" |
| 88 | + ) |
| 89 | + sys.exit(1) |
0 commit comments