Coverage Report

Created: 2025-06-10 06:56

/src/ghostpdl/base/scfparam.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* CCITTFax filter parameter setting and reading */
18
#include "std.h"
19
#include "gserrors.h"
20
#include "gstypes.h"
21
#include "gsmemory.h"
22
#include "gsparam.h"
23
#include "scommon.h"
24
#include "scf.h"    /* for cfe_max_width */
25
#include "scfx.h"
26
27
/* Define the CCITTFax parameters. */
28
static const gs_param_item_t s_CF_param_items[] =
29
{
30
#define cfp(key, type, memb) { key, type, offset_of(stream_CF_state, memb) }
31
    cfp("Uncompressed", gs_param_type_bool, Uncompressed),
32
    cfp("K", gs_param_type_int, K),
33
    cfp("EndOfLine", gs_param_type_bool, EndOfLine),
34
    cfp("EncodedByteAlign", gs_param_type_bool, EncodedByteAlign),
35
    cfp("Columns", gs_param_type_int, Columns),
36
    cfp("Rows", gs_param_type_int, Rows),
37
    cfp("EndOfBlock", gs_param_type_bool, EndOfBlock),
38
    cfp("ErrsAsEOD", gs_param_type_bool, ErrsAsEOD),
39
    cfp("BlackIs1", gs_param_type_bool, BlackIs1),
40
    cfp("DamagedRowsBeforeError", gs_param_type_int, DamagedRowsBeforeError),
41
    cfp("FirstBitLowOrder", gs_param_type_bool, FirstBitLowOrder),
42
    cfp("DecodedByteAlign", gs_param_type_int, DecodedByteAlign),
43
#undef cfp
44
    gs_param_item_end
45
};
46
47
/* Define a limit on the Rows parameter, was too low at 32000 */
48
0
#define cf_max_height 1000000
49
50
/* Get non-default CCITTFax filter parameters. */
51
stream_state_proc_get_params(s_CF_get_params, stream_CF_state);   /* check */
52
int
53
s_CF_get_params(gs_param_list * plist, const stream_CF_state * ss, bool all)
54
0
{
55
0
    stream_CF_state cfs_defaults;
56
0
    const stream_CF_state *defaults;
57
58
0
    if (all)
59
0
        defaults = 0;
60
0
    else {
61
0
        s_CF_set_defaults_inline(&cfs_defaults);
62
0
        defaults = &cfs_defaults;
63
0
    }
64
0
    return gs_param_write_items(plist, ss, defaults, s_CF_param_items);
65
0
}
66
67
/* Put CCITTFax filter parameters. */
68
stream_state_proc_put_params(s_CF_put_params, stream_CF_state);   /* check */
69
int
70
s_CF_put_params(gs_param_list * plist, stream_CF_state * ss)
71
0
{
72
0
    stream_CF_state state;
73
0
    int code;
74
75
0
    state = *ss;
76
0
    code = gs_param_read_items(plist, (void *)&state, s_CF_param_items, NULL);
77
0
    if (code >= 0 &&
78
0
        (state.K < -cf_max_height || state.K > cf_max_height ||
79
0
         state.Columns < 0 || state.Columns > cfe_max_width ||
80
0
         state.Rows < 0 || state.Rows > cf_max_height ||
81
0
         state.DamagedRowsBeforeError < 0 ||
82
0
         state.DamagedRowsBeforeError > cf_max_height ||
83
0
         state.DecodedByteAlign < 1 || state.DecodedByteAlign > 16 ||
84
0
         (state.DecodedByteAlign & (state.DecodedByteAlign - 1)) != 0)
85
0
        )
86
0
        code = gs_note_error(gs_error_rangecheck);
87
0
    if (code >= 0)
88
0
        *ss = state;
89
0
    return code;
90
0
}