1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2023 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import argparse 17import os 18import subprocess 19import sys 20import shutil 21 22def copy_file(dir, dest): 23 src_name = '/cupsfilters.convs.in' 24 dest_name = '/cupsfilters.convs' 25 src_file = dir + src_name 26 dest_file = dest + dest_name 27 shutil.copy2(src_file, dest_file) 28 29def apply_patch(patch_file, target_dir): 30 try: 31 if not os.path.exists(target_dir): 32 return 33 patch_cmd = ['patch', '-p1', "--fuzz=0", "--no-backup-if-mismatch", '-i', patch_file, '-d', target_dir] 34 subprocess.run(patch_cmd, check=True) 35 except Exception as e: 36 print("apply_patch error!") 37 return 38 39 40def do_patch(target_dir): 41 patch_file = [ 42 "ohos_pdftoraster.patch", 43 "ohos_pdf_convs.patch", 44 "backport-CVE-2023-24805.patch", 45 ] 46 47 for patch in patch_file: 48 apply_patch(patch, target_dir) 49 50 51def main(): 52 path = argparse.ArgumentParser() 53 path.add_argument('--gen-dir', help='generate path of log', required=True) 54 path.add_argument('--source-dir', help='generate path of log', required=True) 55 args = path.parse_args() 56 convs_dir = os.path.join(args.source_dir, "mime") 57 58 do_patch(args.source_dir) 59 copy_file(convs_dir, args.gen_dir) 60 return 0 61 62if __name__ == '__main__': 63 sys.exit(main()) 64