From cf9f4b63b8b31e39475d275feab31d411b1d95a3 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 14 Nov 2018 14:46:49 -0800 Subject: [PATCH] fixed fuzz test src code --- doc/zstd_manual.html | 155 ++++++++++++++-------------- lib/zstd.h | 178 ++++++++++++++++----------------- tests/fuzz/simple_round_trip.c | 2 +- tests/fuzz/stream_round_trip.c | 4 +- 4 files changed, 165 insertions(+), 174 deletions(-) diff --git a/doc/zstd_manual.html b/doc/zstd_manual.html index 1bae5c39..3f6b311f 100644 --- a/doc/zstd_manual.html +++ b/doc/zstd_manual.html @@ -19,7 +19,7 @@
  • Streaming compression - HowTo
  • Streaming decompression - HowTo
  • ADVANCED AND EXPERIMENTAL FUNCTIONS
  • -
  • Candidate API for promotion into stable
  • +
  • Candidate API for promotion to stable status
  • Memory management
  • Advanced compression API
  • experimental API (static linking only)
  • @@ -350,9 +350,12 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
    -

    Candidate API for promotion into stable

    - The following symbols and constants are considered to join
    - "stable API" status by v1.4.0
    +

    Candidate API for promotion to stable status

    + The following symbols and constants are currently considered
    + to join "stable API" status by v1.4.0.
    + The intention is that they should be able to become stable "as is", with no further modification.
    + It is also last chance to gather comments / suggestions on this API,
    + as the API is locked once reaching "stable" status.
      
     
    @@ -367,27 +370,11 @@ size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds); size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict); size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);

    These functions give the current memory usage of selected object. - Object memory usage can evolve when re-used. + Object memory usage can evolve (increase or decrease) over time.


    Advanced compression API

    
     
    -
    typedef enum {
    -    /* Opened question : should we have a format ZSTD_f_auto ?
    -     * Today, it would mean exactly the same as ZSTD_f_zstd1.
    -     * But, in the future, should several formats become supported,
    -     * on the compression side, it would mean "default format".
    -     * On the decompression side, it would mean "automatic format detection",
    -     * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames".
    -     * Since meaning is a little different, another option could be to define different enums for compression and decompression.
    -     * This question could be kept for later, when there are actually multiple formats to support,
    -     * but there is also the question of pinning enum values, and pinning value `0` is especially important */
    -    ZSTD_f_zstd1 = 0,           /* zstd frame format, specified in zstd_compression_format.md (default) */
    -    ZSTD_f_zstd1_magicless = 1, /* Variant of zstd frame format, without initial 4-bytes magic number.
    -                                 * Useful to save 4 bytes per generated frame.
    -                                 * Decoder cannot recognise automatically this format, requiring instructions. */
    -} ZSTD_format_e;
    -

    typedef enum { ZSTD_fast=1,
                    ZSTD_dfast=2,
                    ZSTD_greedy=3,
    @@ -399,38 +386,6 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
                    /* note : new strategies might be added in the future */
                } ZSTD_strategy;
     

    -
    typedef enum {
    -    /* Note: this enum and the behavior it controls are effectively internal
    -     * implementation details of the compressor. They are expected to continue
    -     * to evolve and should be considered only in the context of extremely
    -     * advanced performance tuning.
    -     *
    -     * Zstd currently supports the use of a CDict in two ways:
    -     *
    -     * - The contents of the CDict can be copied into the working context. This
    -     *   means that the compression can search both the dictionary and input
    -     *   while operating on a single set of internal tables. This makes
    -     *   the compression faster per-byte of input. However, the initial copy of
    -     *   the CDict's tables incurs a fixed cost at the beginning of the
    -     *   compression. For small compressions (< 8 KB), that copy can dominate
    -     *   the cost of the compression.
    -     *
    -     * - The CDict's tables can be used in-place. In this model, compression is
    -     *   slower per input byte, because the compressor has to search two sets of
    -     *   tables. However, this model incurs no start-up cost (as long as the
    -     *   working context's tables can be reused). For small inputs, this can be
    -     *   faster than copying the CDict's tables.
    -     *
    -     * Zstd has a simple internal heuristic that selects which strategy to use
    -     * at the beginning of a compression. However, if experimentation shows that
    -     * Zstd is making poor choices, it is possible to override that choice with
    -     * this enum.
    -     */
    -    ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
    -    ZSTD_dictForceAttach   = 1, /* Never copy the dictionary. */
    -    ZSTD_dictForceCopy     = 2, /* Always copy the dictionary. */
    -} ZSTD_dictAttachPref_e;
    -

    typedef enum {
     
         /* compression parameters */
    @@ -438,12 +393,11 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
                                   * Default level is ZSTD_CLEVEL_DEFAULT==3.
                                   * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT.
                                   * Note 1 : it's possible to pass a negative compression level by casting it to unsigned type.
    -                              * Note 2 : setting a level sets all default values of other compression parameters.
    -                              * Note 3 : setting compressionLevel automatically updates ZSTD_p_compressLiterals. */
    +                              * Note 2 : setting a level sets all default values of other compression parameters */
         ZSTD_p_windowLog=101,    /* Maximum allowed back-reference distance, expressed as power of 2.
                                   * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
                                   * Special: value 0 means "use default windowLog".
    -                              * Note: Using a window size greater than ZSTD_MAXWINDOWSIZE_DEFAULT (default: 2^27)
    +                              * Note: Using a window size greater than 1</* Size of the initial probe table, as a power of 2.
                                   * Resulting table size is (1 << (hashLog+2)).
    @@ -519,7 +473,7 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
         ZSTD_p_dictIDFlag=202,   /* When applicable, dictionary's ID is written into frame header (default:1) */
     
         /* multi-threading parameters */
    -    /* These parameters are only useful if multi-threading is enabled (ZSTD_MULTITHREAD).
    +    /* These parameters are only useful if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD).
          * They return an error otherwise. */
         ZSTD_p_nbWorkers=400,    /* Select how many threads will be spawned to compress in parallel.
                                   * When nbWorkers >= 1, triggers asynchronous mode :
    @@ -528,17 +482,17 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
                                   * (note : a strong exception to this rule is when first invocation sets ZSTD_e_end : it becomes a blocking call).
                                   * More workers improve speed, but also increase memory usage.
                                   * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */
    -    ZSTD_p_jobSize=401,      /* Size of a compression job. This value is enforced only in non-blocking mode.
    -                              * Each compression job is completed in parallel, so this value indirectly controls the nb of active threads.
    +    ZSTD_p_jobSize=401,      /* Size of a compression job. This value is enforced only when nbWorkers >= 1.
    +                              * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads.
                                   * 0 means default, which is dynamically determined based on compression parameters.
                                   * Job size must be a minimum of overlapSize, or 1 MB, whichever is largest.
                                   * The minimum size is automatically and transparently enforced */
    -    ZSTD_p_overlapSizeLog=402, /* Size of previous input reloaded at the beginning of each job.
    -                              * 0 => no overlap, 6(default) => use 1/8th of windowSize, >=9 => use full windowSize */
    +    ZSTD_p_overlapSizeLog=402, /* Size of previous input reloaded at the beginning of each job, as a fraction of window size.
    +                              * 0 : no overlap;  6(default) : use 1/8th of windowSize;  >=9 : use full windowSize */
     
         /* =================================================================== */
         /* experimental parameters - no stability guaranteed                   */
    -    /* note : should this be exported in a different section of zstd.h ?   */
    +    /* => note : should this part be exported in a different section of zstd.h ? */
         /* =================================================================== */
     
         /* compression format */
    @@ -569,12 +523,6 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
                 or an error code (which can be tested with ZSTD_isError()). 
     


    -
    size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned* value);
    -

    Get the requested value of one compression parameter, selected by enum ZSTD_cParameter. - @result : 0, or an error code (which can be tested with ZSTD_isError()). - -


    -
    size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize);
     

    Total input data size to be compressed as a single frame. This value will be controlled at end of frame, and trigger an error if not respected. @@ -644,29 +592,27 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); } ZSTD_CCtx_reset_directive;


    size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_CCtx_reset_directive zcrd);
    -

    Return a CCtx to clean state. - There 2 things that can be reset, independently or jointly : - - The session : will stop compressing current frame, and stand ready to start a new one. - This action never fails. +

    There are 2 different things that can be reset, independently or jointly : + - The session : will stop compressing current frame, and make CCtx ready to start a new one. Useful after an error, or to interrupt any ongoing compression. Any internal data not yet flushed is cancelled. But parameters and dictionary are kept unchanged. Therefore, same parameters and dictionary will be used for next frame. + This action never fails. - The parameters : changes all parameters back to "default". - This removes any dictionary too. + This removes any reference to any dictionary too. Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing) otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError()) - Both : similar to resetting the session, followed by resetting parameters. - This action never fails.


    typedef enum {
         ZSTD_e_continue=0, /* collect more data, encoder decides when to output compressed result, for optimal compression ratio */
    -    ZSTD_e_flush,      /* flush any data provided so far,
    +    ZSTD_e_flush=1,    /* flush any data provided so far,
                             * it creates (at least) one new block, that can be decoded immediately on reception;
                             * frame will continue: any future data can still reference previously compressed data, improving compression. */
    -    ZSTD_e_end         /* flush any remaining data and close current frame.
    +    ZSTD_e_end=2       /* flush any remaining data and close current frame.
                             * any additional data starts a new frame.
                             * each frame is independent (does not reference any content from previous frame). */
     } ZSTD_EndDirective;
    @@ -704,8 +650,7 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
                     ZSTD_EndDirective endOp);
     

    Same as ZSTD_compress_generic(), but using only integral types as arguments. - Argument list is larger than ZSTD_{in,out}Buffer, - but can be helpful for binders from dynamic languages + This variant might be be helpful for binders from dynamic languages which have troubles handling structures containing memory pointers.


    @@ -750,6 +695,54 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); ZSTD_dlm_byRef = 1, /**< Reference dictionary content -- the dictionary buffer must outlive its users. */ } ZSTD_dictLoadMethod_e;
    +
    typedef enum {
    +    /* Opened question : should we have a format ZSTD_f_auto ?
    +     * Today, it would mean exactly the same as ZSTD_f_zstd1.
    +     * But, in the future, should several formats become supported,
    +     * on the compression side, it would mean "default format".
    +     * On the decompression side, it would mean "automatic format detection",
    +     * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames".
    +     * Since meaning is a little different, another option could be to define different enums for compression and decompression.
    +     * This question could be kept for later, when there are actually multiple formats to support,
    +     * but there is also the question of pinning enum values, and pinning value `0` is especially important */
    +    ZSTD_f_zstd1 = 0,           /* zstd frame format, specified in zstd_compression_format.md (default) */
    +    ZSTD_f_zstd1_magicless = 1, /* Variant of zstd frame format, without initial 4-bytes magic number.
    +                                 * Useful to save 4 bytes per generated frame.
    +                                 * Decoder cannot recognise automatically this format, requiring instructions. */
    +} ZSTD_format_e;
    +

    +
    typedef enum {
    +    /* Note: this enum and the behavior it controls are effectively internal
    +     * implementation details of the compressor. They are expected to continue
    +     * to evolve and should be considered only in the context of extremely
    +     * advanced performance tuning.
    +     *
    +     * Zstd currently supports the use of a CDict in two ways:
    +     *
    +     * - The contents of the CDict can be copied into the working context. This
    +     *   means that the compression can search both the dictionary and input
    +     *   while operating on a single set of internal tables. This makes
    +     *   the compression faster per-byte of input. However, the initial copy of
    +     *   the CDict's tables incurs a fixed cost at the beginning of the
    +     *   compression. For small compressions (< 8 KB), that copy can dominate
    +     *   the cost of the compression.
    +     *
    +     * - The CDict's tables can be used in-place. In this model, compression is
    +     *   slower per input byte, because the compressor has to search two sets of
    +     *   tables. However, this model incurs no start-up cost (as long as the
    +     *   working context's tables can be reused). For small inputs, this can be
    +     *   faster than copying the CDict's tables.
    +     *
    +     * Zstd has a simple internal heuristic that selects which strategy to use
    +     * at the beginning of a compression. However, if experimentation shows that
    +     * Zstd is making poor choices, it is possible to override that choice with
    +     * this enum.
    +     */
    +    ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
    +    ZSTD_dictForceAttach   = 1, /* Never copy the dictionary. */
    +    ZSTD_dictForceCopy     = 2, /* Always copy the dictionary. */
    +} ZSTD_dictAttachPref_e;
    +

    Frame size functions

    
     
     
    size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
    @@ -927,6 +920,12 @@ static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };  /**< t
       and how to interpret prefix content (automatic ? force raw mode (default) ? full mode only ?) 
     


    +
    size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned* value);
    +

    Get the requested value of one compression parameter, selected by enum ZSTD_cParameter. + @result : 0, or an error code (which can be tested with ZSTD_isError()). + +


    +
    ZSTD_CCtx_params* ZSTD_createCCtxParams(void);
     size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params);
     

    Quick howto : diff --git a/lib/zstd.h b/lib/zstd.h index ed9747ed..1f9e66e4 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -406,10 +406,13 @@ ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output /**************************************************************************************** - * Candidate API for promotion into stable + * Candidate API for promotion to stable status **************************************************************************************** - * The following symbols and constants are considered to join - * "stable API" status by v1.4.0 + * The following symbols and constants are currently considered + * to join "stable API" status by v1.4.0. + * The intention is that they should be able to become stable "as is", with no further modification. + * It is also last chance to gather comments / suggestions on this API, + * as the API is locked once reaching "stable" status. * ***************************************************************************************/ ZSTDLIB_API int ZSTD_minCLevel(void); /*!< minimum negative compression level allowed */ @@ -419,14 +422,15 @@ ZSTDLIB_API int ZSTD_minCLevel(void); /*!< minimum negative compression level a /* all magic numbers are supposed read/written to/from files/memory using little-endian convention */ #define ZSTD_MAGICNUMBER 0xFD2FB528 /* valid since v0.8.0 */ #define ZSTD_MAGIC_DICTIONARY 0xEC30A437 /* valid since v0.7.0 */ -#define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50 /* all 16 values, from 0x184D2A50 to 0x184D2A5F, are understood as skippable frames */ +#define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50 /* all 16 values, from 0x184D2A50 to 0x184D2A5F, signal the beginning of a skippable frame */ #define ZSTD_MAGIC_SKIPPABLE_MASK 0xFFFFFFF0 -/* note : should this limit be smaller ? like 23 (8 MB) as recommended in the spec ? - * also: could it be different from zstd cli default limit, which is designed to match LDM default (27) ? */ +/* note : should this limit be smaller ? like 23 (8 MB) as suggested in the spec ? + * can it be different from zstd cli default limit, which is designed to match --ultra and --long default (27) ? */ #define ZSTD_WINDOWLOG_LIMIT_DEFAULT 27 /* by default, the streaming decoder will refuse any frame * requiring larger than (1<= 1, triggers asynchronous mode : @@ -651,17 +601,17 @@ typedef enum { * (note : a strong exception to this rule is when first invocation sets ZSTD_e_end : it becomes a blocking call). * More workers improve speed, but also increase memory usage. * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */ - ZSTD_p_jobSize=401, /* Size of a compression job. This value is enforced only in non-blocking mode. - * Each compression job is completed in parallel, so this value indirectly controls the nb of active threads. + ZSTD_p_jobSize=401, /* Size of a compression job. This value is enforced only when nbWorkers >= 1. + * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads. * 0 means default, which is dynamically determined based on compression parameters. * Job size must be a minimum of overlapSize, or 1 MB, whichever is largest. * The minimum size is automatically and transparently enforced */ - ZSTD_p_overlapSizeLog=402, /* Size of previous input reloaded at the beginning of each job. - * 0 => no overlap, 6(default) => use 1/8th of windowSize, >=9 => use full windowSize */ + ZSTD_p_overlapSizeLog=402, /* Size of previous input reloaded at the beginning of each job, as a fraction of window size. + * 0 : no overlap; 6(default) : use 1/8th of windowSize; >=9 : use full windowSize */ /* =================================================================== */ /* experimental parameters - no stability guaranteed */ - /* note : should this be exported in a different section of zstd.h ? */ + /* => note : should this part be exported in a different section of zstd.h ? */ /* =================================================================== */ /* compression format */ @@ -693,12 +643,6 @@ typedef enum { * or an error code (which can be tested with ZSTD_isError()). */ ZSTDLIB_API size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned value); -/*! ZSTD_CCtx_getParameter() : - * Get the requested value of one compression parameter, selected by enum ZSTD_cParameter. - * @result : 0, or an error code (which can be tested with ZSTD_isError()). - */ -ZSTDLIB_API size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned* value); - /*! ZSTD_CCtx_setPledgedSrcSize() : * Total input data size to be compressed as a single frame. * This value will be controlled at end of frame, and trigger an error if not respected. @@ -769,20 +713,18 @@ typedef enum { } ZSTD_CCtx_reset_directive; /*! ZSTD_CCtx_reset() : - * Return a CCtx to clean state. - * There 2 things that can be reset, independently or jointly : - * - The session : will stop compressing current frame, and stand ready to start a new one. - * This action never fails. + * There are 2 different things that can be reset, independently or jointly : + * - The session : will stop compressing current frame, and make CCtx ready to start a new one. * Useful after an error, or to interrupt any ongoing compression. * Any internal data not yet flushed is cancelled. * But parameters and dictionary are kept unchanged. * Therefore, same parameters and dictionary will be used for next frame. + * This action never fails. * - The parameters : changes all parameters back to "default". - * This removes any dictionary too. + * This removes any reference to any dictionary too. * Parameters can only be changed between 2 sessions (i.e. no compression is currently ongoing) * otherwise the reset fails, and function returns an error value (which can be tested using ZSTD_isError()) * - Both : similar to resetting the session, followed by resetting parameters. - * This action never fails. */ ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_CCtx_reset_directive zcrd); @@ -790,10 +732,10 @@ ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_CCtx_reset_directive zc typedef enum { ZSTD_e_continue=0, /* collect more data, encoder decides when to output compressed result, for optimal compression ratio */ - ZSTD_e_flush, /* flush any data provided so far, + ZSTD_e_flush=1, /* flush any data provided so far, * it creates (at least) one new block, that can be decoded immediately on reception; * frame will continue: any future data can still reference previously compressed data, improving compression. */ - ZSTD_e_end /* flush any remaining data and close current frame. + ZSTD_e_end=2 /* flush any remaining data and close current frame. * any additional data starts a new frame. * each frame is independent (does not reference any content from previous frame). */ } ZSTD_EndDirective; @@ -828,8 +770,7 @@ ZSTDLIB_API size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, /*! ZSTD_compress_generic_simpleArgs() : * Same as ZSTD_compress_generic(), * but using only integral types as arguments. - * Argument list is larger than ZSTD_{in,out}Buffer, - * but can be helpful for binders from dynamic languages + * This variant might be be helpful for binders from dynamic languages * which have troubles handling structures containing memory pointers. */ ZSTDLIB_API size_t ZSTD_compress_generic_simpleArgs ( @@ -895,6 +836,53 @@ typedef enum { ZSTD_dlm_byRef = 1, /**< Reference dictionary content -- the dictionary buffer must outlive its users. */ } ZSTD_dictLoadMethod_e; +typedef enum { + /* Opened question : should we have a format ZSTD_f_auto ? + * Today, it would mean exactly the same as ZSTD_f_zstd1. + * But, in the future, should several formats become supported, + * on the compression side, it would mean "default format". + * On the decompression side, it would mean "automatic format detection", + * so that ZSTD_f_zstd1 would mean "accept *only* zstd frames". + * Since meaning is a little different, another option could be to define different enums for compression and decompression. + * This question could be kept for later, when there are actually multiple formats to support, + * but there is also the question of pinning enum values, and pinning value `0` is especially important */ + ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */ + ZSTD_f_zstd1_magicless = 1, /* Variant of zstd frame format, without initial 4-bytes magic number. + * Useful to save 4 bytes per generated frame. + * Decoder cannot recognise automatically this format, requiring instructions. */ +} ZSTD_format_e; + +typedef enum { + /* Note: this enum and the behavior it controls are effectively internal + * implementation details of the compressor. They are expected to continue + * to evolve and should be considered only in the context of extremely + * advanced performance tuning. + * + * Zstd currently supports the use of a CDict in two ways: + * + * - The contents of the CDict can be copied into the working context. This + * means that the compression can search both the dictionary and input + * while operating on a single set of internal tables. This makes + * the compression faster per-byte of input. However, the initial copy of + * the CDict's tables incurs a fixed cost at the beginning of the + * compression. For small compressions (< 8 KB), that copy can dominate + * the cost of the compression. + * + * - The CDict's tables can be used in-place. In this model, compression is + * slower per input byte, because the compressor has to search two sets of + * tables. However, this model incurs no start-up cost (as long as the + * working context's tables can be reused). For small inputs, this can be + * faster than copying the CDict's tables. + * + * Zstd has a simple internal heuristic that selects which strategy to use + * at the beginning of a compression. However, if experimentation shows that + * Zstd is making poor choices, it is possible to override that choice with + * this enum. + */ + ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */ + ZSTD_dictForceAttach = 1, /* Never copy the dictionary. */ + ZSTD_dictForceCopy = 2, /* Always copy the dictionary. */ +} ZSTD_dictAttachPref_e; /*************************************** @@ -1115,6 +1103,12 @@ ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx* cctx, const void * and how to interpret prefix content (automatic ? force raw mode (default) ? full mode only ?) */ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType); +/*! ZSTD_CCtx_getParameter() : + * Get the requested value of one compression parameter, selected by enum ZSTD_cParameter. + * @result : 0, or an error code (which can be tested with ZSTD_isError()). + */ +ZSTDLIB_API size_t ZSTD_CCtx_getParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned* value); + /*! ZSTD_CCtx_params : * Quick howto : @@ -1136,7 +1130,6 @@ ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* pre ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void); ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params); - /*! ZSTD_CCtxParams_reset() : * Reset params to default values. */ @@ -1154,7 +1147,6 @@ ZSTDLIB_API size_t ZSTD_CCtxParams_init(ZSTD_CCtx_params* cctxParams, int compre */ ZSTDLIB_API size_t ZSTD_CCtxParams_init_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params); - /*! ZSTD_CCtxParam_setParameter() : * Similar to ZSTD_CCtx_setParameter. * Set one compression parameter, selected by enum ZSTD_cParameter. diff --git a/tests/fuzz/simple_round_trip.c b/tests/fuzz/simple_round_trip.c index 0921106d..5474d756 100644 --- a/tests/fuzz/simple_round_trip.c +++ b/tests/fuzz/simple_round_trip.c @@ -40,7 +40,7 @@ static size_t roundTripTest(void *result, size_t resultCapacity, ZSTD_outBuffer out = {compressed, compressedCapacity, 0}; size_t err; - ZSTD_CCtx_reset(cctx); + ZSTD_CCtx_reset(cctx, ZSTD_CCtx_reset_session_only); FUZZ_setRandomParameters(cctx, srcSize, &seed); err = ZSTD_compress_generic(cctx, &out, &in, ZSTD_e_end); FUZZ_ZASSERT(err); diff --git a/tests/fuzz/stream_round_trip.c b/tests/fuzz/stream_round_trip.c index 72d70495..b04f6fdc 100644 --- a/tests/fuzz/stream_round_trip.c +++ b/tests/fuzz/stream_round_trip.c @@ -56,7 +56,7 @@ static size_t compress(uint8_t *dst, size_t capacity, const uint8_t *src, size_t srcSize) { size_t dstSize = 0; - ZSTD_CCtx_reset(cctx); + ZSTD_CCtx_reset(cctx, ZSTD_CCtx_reset_session_only); FUZZ_setRandomParameters(cctx, srcSize, &seed); while (srcSize > 0) { @@ -84,7 +84,7 @@ static size_t compress(uint8_t *dst, size_t capacity, FUZZ_ZASSERT(ret); /* Reset the compressor when the frame is finished */ if (ret == 0) { - ZSTD_CCtx_reset(cctx); + ZSTD_CCtx_reset(cctx, ZSTD_CCtx_reset_session_only); if ((FUZZ_rand(&seed) & 7) == 0) { size_t const remaining = in.size - in.pos; FUZZ_setRandomParameters(cctx, remaining, &seed);