Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libpff/libfmapi/libfmapi_lzfu.c
Line
Count
Source
1
/*
2
 * LZFu (de)compression functions
3
 *
4
 * Copyright (C) 2009-2026, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <byte_stream.h>
24
#include <memory.h>
25
#include <types.h>
26
27
#include "libfmapi_checksum.h"
28
#include "libfmapi_libcerror.h"
29
#include "libfmapi_libcnotify.h"
30
#include "libfmapi_lzfu.h"
31
32
692
#define LIBFMAPI_LZFU_SIGNATURE_COMPRESSED        0x75465a4c
33
294
#define LIBFMAPI_LZFU_SIGNATURE_UNCOMPRESSED      0x414c454d
34
35
const char *libfmapi_lzfu_rtf_dictionary = \
36
  "{\\rtf1\\ansi\\mac\\deff0\\deftab720"
37
  "{\\fonttbl;}"
38
  "{\\f0\\fnil \\froman \\fswiss \\fmodern \\fscript \\fdecor MS Sans SerifSymbolArialTimes New RomanCourier"
39
  "{\\colortbl\\red0\\green0\\blue0\r\n\\par \\pard\\plain\\f0\\fs20\\b\\i\\u\\tab\\tx";
40
41
/* Determines the uncompressed data size from the LZFu header in the compressed data
42
 * Returns 1 on success or -1 on error
43
 */
44
int libfmapi_lzfu_get_uncompressed_data_size(
45
     const uint8_t *compressed_data,
46
     size_t compressed_data_size,
47
     size_t *uncompressed_data_size,
48
     libcerror_error_t **error )
49
352
{
50
352
  libfmapi_lzfu_header_t lzfu_header;
51
52
352
  static char *function              = "libfmapi_lzfu_get_uncompressed_data_size";
53
352
  size_t compressed_data_offset      = 0;
54
55
#if defined( HAVE_DEBUG_OUTPUT )
56
  uint8_t lz_buffer[ 4096 ];
57
58
  const uint8_t *lzfu_reference_data = NULL;
59
  size_t uncompressed_data_offset    = 0;
60
  uint16_t lz_buffer_iterator        = 0;
61
  uint16_t reference_iterator        = 0;
62
  uint16_t reference_offset          = 0;
63
  uint16_t reference_size            = 0;
64
  uint8_t flag_byte                  = 0;
65
  uint8_t flag_byte_bit_mask         = 0;
66
#endif
67
68
352
  if( compressed_data == NULL )
69
0
  {
70
0
    libcerror_error_set(
71
0
     error,
72
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
73
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
74
0
     "%s: invalid compressed data.",
75
0
     function );
76
77
0
    return( -1 );
78
0
  }
79
352
  if( ( compressed_data_size < sizeof( libfmapi_lzfu_header_t ) )
80
346
   || ( compressed_data_size > (size_t) SSIZE_MAX ) )
81
6
  {
82
6
    libcerror_error_set(
83
6
     error,
84
6
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
85
6
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
86
6
     "%s: invalid compressed data size value out of bounds.",
87
6
     function );
88
89
6
    return( -1 );
90
6
  }
91
346
  if( uncompressed_data_size == NULL )
92
0
  {
93
0
    libcerror_error_set(
94
0
     error,
95
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
96
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
97
0
     "%s: invalid uncompressed data size.",
98
0
     function );
99
100
0
    return( -1 );
101
0
  }
102
346
  byte_stream_copy_to_uint32_little_endian(
103
346
   &( compressed_data[ compressed_data_offset ] ),
104
346
   lzfu_header.compressed_data_size );
105
106
346
  compressed_data_offset += 4;
107
108
346
  byte_stream_copy_to_uint32_little_endian(
109
346
   &( compressed_data[ compressed_data_offset ] ),
110
346
   lzfu_header.uncompressed_data_size );
111
112
346
  compressed_data_offset += 4;
113
114
346
  byte_stream_copy_to_uint32_little_endian(
115
346
   &( compressed_data[ compressed_data_offset ] ),
116
346
   lzfu_header.signature );
117
118
346
  compressed_data_offset += 8;
119
120
346
  if( ( lzfu_header.signature != LIBFMAPI_LZFU_SIGNATURE_COMPRESSED )
121
147
   && ( lzfu_header.signature != LIBFMAPI_LZFU_SIGNATURE_UNCOMPRESSED ) )
122
85
  {
123
85
    libcerror_error_set(
124
85
     error,
125
85
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
126
85
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
127
85
     "%s: unsupported compression signature: 0x%08" PRIx32 ".",
128
85
     function,
129
85
     lzfu_header.signature );
130
131
85
    return( -1 );
132
85
  }
133
  /* The compressed data size includes 12 bytes of the header
134
   */
135
261
  if( ( lzfu_header.compressed_data_size < 12 )
136
258
   || ( (size_t) ( lzfu_header.compressed_data_size - 12 ) != ( compressed_data_size - sizeof( libfmapi_lzfu_header_t ) ) ) )
137
79
  {
138
79
    libcerror_error_set(
139
79
     error,
140
79
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
141
79
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
142
79
     "%s: mismatch in compressed data size (%" PRIu32 " != %" PRIzd ").",
143
79
     function,
144
79
     lzfu_header.compressed_data_size,
145
79
     compressed_data_size );
146
147
79
    return( -1 );
148
79
  }
149
182
  lzfu_header.compressed_data_size -= 12;
150
151
#if defined( HAVE_DEBUG_OUTPUT )
152
  if( libcnotify_verbose != 0 )
153
  {
154
    if( memory_copy(
155
         lz_buffer,
156
         libfmapi_lzfu_rtf_dictionary,
157
         207 ) == NULL )
158
    {
159
      libcerror_error_set(
160
       error,
161
       LIBCERROR_ERROR_DOMAIN_MEMORY,
162
       LIBCERROR_MEMORY_ERROR_COPY_FAILED,
163
       "%s: unable to initialize lz buffer.",
164
       function );
165
166
      return( -1 );
167
    }
168
    lz_buffer_iterator = 207;
169
170
    if( memory_set(
171
         &( lz_buffer[ lz_buffer_iterator ] ),
172
         0,
173
         4096 - lz_buffer_iterator ) == NULL )
174
    {
175
      libcerror_error_set(
176
       error,
177
       LIBCERROR_ERROR_DOMAIN_MEMORY,
178
       LIBCERROR_MEMORY_ERROR_SET_FAILED,
179
       "%s: unable to clear lz buffer.",
180
       function );
181
182
      return( -1 );
183
    }
184
    while( compressed_data_offset < compressed_data_size )
185
    {
186
      flag_byte = compressed_data[ compressed_data_offset++ ];
187
188
      /* Check every bit in the chunk flag byte from LSB to MSB
189
       */
190
      for( flag_byte_bit_mask = 0x01;
191
           flag_byte_bit_mask != 0x00;
192
           flag_byte_bit_mask <<= 1 )
193
      {
194
        if( compressed_data_offset == compressed_data_size )
195
        {
196
          break;
197
        }
198
        /* Check if the byte value is a literal or a reference
199
         */
200
        if( ( flag_byte & flag_byte_bit_mask ) == 0 )
201
        {
202
          lz_buffer[ lz_buffer_iterator++ ] = compressed_data[ compressed_data_offset ];
203
204
          compressed_data_offset++;
205
          uncompressed_data_offset++;
206
207
          /* Make sure the lz buffer iterator wraps around
208
           */
209
          lz_buffer_iterator %= 4096;
210
211
          lz_buffer[ lz_buffer_iterator ] = 0;
212
        }
213
        else
214
        {
215
          lzfu_reference_data = &( compressed_data[ compressed_data_offset ] );
216
217
          compressed_data_offset += 2;
218
219
          byte_stream_copy_to_uint16_big_endian(
220
           lzfu_reference_data,
221
           reference_offset );
222
223
          reference_size     = ( reference_offset & 0x000f ) + 2;
224
          reference_offset >>= 4;
225
226
          for( reference_iterator = 0; reference_iterator < reference_size; reference_iterator++ )
227
          {
228
            lz_buffer[ lz_buffer_iterator++ ] = lz_buffer[ reference_offset ];
229
230
            uncompressed_data_offset++;
231
            reference_offset++;
232
233
            /* Make sure the lz buffer iterator and reference offset wrap around
234
             */
235
            lz_buffer_iterator %= 4096;
236
            reference_offset   %= 4096;
237
238
            lz_buffer[ lz_buffer_iterator ] = 0;
239
          }
240
        }
241
      }
242
    }
243
    if( (size_t) ( lzfu_header.uncompressed_data_size + 2 ) != uncompressed_data_offset )
244
    {
245
      libcnotify_printf(
246
       "%s: mismatch in uncompressed data size (in header: %" PRIu32 " != required: %" PRIzd ").\n",
247
       function,
248
       lzfu_header.uncompressed_data_size + 2,
249
       uncompressed_data_offset );
250
    }
251
  }
252
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
253
254
  /* Compensate for the 2 trailing zero bytes
255
   */
256
182
  *uncompressed_data_size = lzfu_header.uncompressed_data_size + 2;
257
258
182
  return( 1 );
259
261
}
260
261
/* Decompresses data using LZFu compression
262
 * Returns 1 on success or -1 on error
263
 */
264
int libfmapi_lzfu_decompress(
265
     const uint8_t *compressed_data,
266
     size_t compressed_data_size,
267
     uint8_t *uncompressed_data,
268
     size_t *uncompressed_data_size,
269
     libcerror_error_t **error )
270
352
{
271
352
  libfmapi_lzfu_header_t lzfu_header;
272
273
352
  uint8_t lz_buffer[ 4096 ];
274
275
352
  const uint8_t *lzfu_reference_data = NULL;
276
352
  static char *function              = "libfmapi_lzfu_decompress";
277
352
  size_t compressed_data_offset      = 0;
278
352
  size_t safe_uncompressed_data_size = 0;
279
352
  size_t uncompressed_data_offset    = 0;
280
352
  uint32_t calculated_checksum       = 0;
281
352
  uint16_t lz_buffer_iterator        = 0;
282
352
  uint16_t reference_iterator        = 0;
283
352
  uint16_t reference_offset          = 0;
284
352
  uint16_t reference_size            = 0;
285
352
  uint8_t flag_byte                  = 0;
286
352
  uint8_t flag_byte_bit_mask         = 0;
287
288
352
  if( compressed_data == NULL )
289
0
  {
290
0
    libcerror_error_set(
291
0
     error,
292
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
293
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
294
0
     "%s: invalid compressed data.",
295
0
     function );
296
297
0
    return( -1 );
298
0
  }
299
352
  if( ( compressed_data_size < sizeof( libfmapi_lzfu_header_t ) )
300
346
   || ( compressed_data_size > (size_t) SSIZE_MAX ) )
301
6
  {
302
6
    libcerror_error_set(
303
6
     error,
304
6
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
305
6
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
306
6
     "%s: invalid compressed data size value out of bounds.",
307
6
     function );
308
309
6
    return( -1 );
310
6
  }
311
346
  if( uncompressed_data == NULL )
312
0
  {
313
0
    libcerror_error_set(
314
0
     error,
315
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
316
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
317
0
     "%s: invalid uncompressed data.",
318
0
     function );
319
320
0
    return( -1 );
321
0
  }
322
346
  if( uncompressed_data_size == NULL )
323
0
  {
324
0
    libcerror_error_set(
325
0
     error,
326
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
327
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
328
0
     "%s: invalid uncompressed data size.",
329
0
     function );
330
331
0
    return( -1 );
332
0
  }
333
346
  safe_uncompressed_data_size = *uncompressed_data_size;
334
335
#if defined( HAVE_DEBUG_OUTPUT )
336
  if( libcnotify_verbose != 0 )
337
  {
338
    libcnotify_printf(
339
     "%s: LZFu compressed data:\n",
340
     function );
341
    libcnotify_print_data(
342
     compressed_data,
343
     compressed_data_size,
344
     0 );
345
  }
346
#endif
347
346
  if( memory_copy(
348
346
       lz_buffer,
349
346
       libfmapi_lzfu_rtf_dictionary,
350
346
       207 ) == NULL )
351
0
  {
352
0
    libcerror_error_set(
353
0
     error,
354
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
355
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
356
0
     "%s: unable to initialize lz buffer.",
357
0
     function );
358
359
0
    return( -1 );
360
0
  }
361
346
  lz_buffer_iterator = 207;
362
363
346
  if( memory_set(
364
346
       &( lz_buffer[ lz_buffer_iterator ] ),
365
346
       0,
366
346
       4096 - lz_buffer_iterator ) == NULL )
367
0
  {
368
0
    libcerror_error_set(
369
0
     error,
370
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
371
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
372
0
     "%s: unable to clear lz buffer.",
373
0
     function );
374
375
0
    return( -1 );
376
0
  }
377
346
  byte_stream_copy_to_uint32_little_endian(
378
346
   &( compressed_data[ compressed_data_offset ] ),
379
346
   lzfu_header.compressed_data_size );
380
381
346
  compressed_data_offset += 4;
382
383
346
  byte_stream_copy_to_uint32_little_endian(
384
346
   &( compressed_data[ compressed_data_offset ] ),
385
346
   lzfu_header.uncompressed_data_size );
386
387
346
  compressed_data_offset += 4;
388
389
346
  byte_stream_copy_to_uint32_little_endian(
390
346
   &( compressed_data[ compressed_data_offset ] ),
391
346
   lzfu_header.signature );
392
393
346
  compressed_data_offset += 4;
394
395
346
  byte_stream_copy_to_uint32_little_endian(
396
346
   &( compressed_data[ compressed_data_offset ] ),
397
346
   lzfu_header.checksum );
398
399
346
  compressed_data_offset += 4;
400
401
#if defined( HAVE_DEBUG_OUTPUT )
402
  if( libcnotify_verbose != 0 )
403
  {
404
    libcnotify_printf(
405
     "%s: lzfu header compressed data size\t\t: %" PRIu32 "\n",
406
     function,
407
     lzfu_header.compressed_data_size );
408
409
    libcnotify_printf(
410
     "%s: lzfu header uncompressed data size\t\t: %" PRIu32 "\n",
411
     function,
412
     lzfu_header.uncompressed_data_size );
413
414
    libcnotify_printf(
415
     "%s: lzfu header signature\t\t\t\t: 0x08%" PRIx32 "\n",
416
     function,
417
     lzfu_header.signature );
418
419
    libcnotify_printf(
420
     "%s: lzfu header checksum\t\t\t\t: %" PRIu32 "\n",
421
     function,
422
     lzfu_header.checksum );
423
  }
424
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
425
426
346
  if( ( lzfu_header.signature != LIBFMAPI_LZFU_SIGNATURE_COMPRESSED )
427
147
   && ( lzfu_header.signature != LIBFMAPI_LZFU_SIGNATURE_UNCOMPRESSED ) )
428
85
  {
429
85
    libcerror_error_set(
430
85
     error,
431
85
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
432
85
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
433
85
     "%s: unsupported compression signature: 0x%08" PRIx32 ".",
434
85
     function,
435
85
     lzfu_header.signature );
436
437
85
    return( -1 );
438
85
  }
439
  /* The compressed data size includes 12 bytes of the header
440
   */
441
261
  if( ( lzfu_header.compressed_data_size < 12 )
442
258
   || ( (size_t) ( lzfu_header.compressed_data_size - 12 ) != ( compressed_data_size - sizeof( libfmapi_lzfu_header_t ) ) ) )
443
79
  {
444
79
    libcerror_error_set(
445
79
     error,
446
79
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
447
79
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
448
79
     "%s: mismatch in compressed data size (%" PRIu32 " != %" PRIzd ").",
449
79
     function,
450
79
     lzfu_header.compressed_data_size,
451
79
     compressed_data_size );
452
453
79
    return( -1 );
454
79
  }
455
182
  lzfu_header.compressed_data_size -= 12;
456
457
  /* Make sure the uncompressed buffer is large enough
458
   */
459
182
  if( safe_uncompressed_data_size < lzfu_header.uncompressed_data_size )
460
15
  {
461
15
    libcerror_error_set(
462
15
     error,
463
15
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
464
15
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
465
15
     "%s: uncompressed data too small.",
466
15
     function );
467
468
15
    *uncompressed_data_size = lzfu_header.uncompressed_data_size;
469
470
15
    return( -1 );
471
15
  }
472
167
  if( libfmapi_checksum_calculate_weak_crc32(
473
167
       &calculated_checksum,
474
167
       &( compressed_data[ compressed_data_offset ] ),
475
167
       (size_t) lzfu_header.compressed_data_size,
476
167
       0,
477
167
       error ) != 1 )
478
0
  {
479
0
    libcerror_error_set(
480
0
     error,
481
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
482
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
483
0
     "%s: unable to calculate weak CRC-32.",
484
0
     function );
485
486
0
    return( -1 );
487
0
  }
488
167
  if( lzfu_header.checksum != calculated_checksum )
489
57
  {
490
57
    libcerror_error_set(
491
57
     error,
492
57
     LIBCERROR_ERROR_DOMAIN_INPUT,
493
57
     LIBCERROR_INPUT_ERROR_CHECKSUM_MISMATCH,
494
57
     "%s: mismatch in checksum ( %" PRIu32 " != %" PRIu32 " ).",
495
57
     function,
496
57
     lzfu_header.checksum,
497
57
     calculated_checksum );
498
499
57
    return( -1 );
500
57
  }
501
83.2k
  while( compressed_data_offset < compressed_data_size )
502
83.2k
  {
503
83.2k
    flag_byte = compressed_data[ compressed_data_offset++ ];
504
505
    /* Check every bit in the chunk flag byte from LSB to MSB
506
     */
507
83.2k
    for( flag_byte_bit_mask = 0x01;
508
748k
         flag_byte_bit_mask != 0x00;
509
665k
         flag_byte_bit_mask <<= 1 )
510
665k
    {
511
665k
      if( compressed_data_offset == compressed_data_size )
512
54
      {
513
54
        break;
514
54
      }
515
      /* Check if the byte value is a literal or a reference
516
       */
517
665k
      if( ( flag_byte & flag_byte_bit_mask ) == 0 )
518
493k
      {
519
493k
        if( compressed_data_offset >= compressed_data_size )
520
0
        {
521
0
          libcerror_error_set(
522
0
           error,
523
0
           LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
524
0
           LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
525
0
           "%s: missing compressed data.",
526
0
           function );
527
528
0
          *uncompressed_data_size = 0;
529
530
0
          return( -1 );
531
0
        }
532
493k
        if( uncompressed_data_offset >= safe_uncompressed_data_size )
533
5
        {
534
5
          libcerror_error_set(
535
5
           error,
536
5
           LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
537
5
           LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
538
5
           "%s: uncompressed data too small.",
539
5
           function );
540
541
5
          *uncompressed_data_size = uncompressed_data_offset;
542
543
5
          return( -1 );
544
5
        }
545
493k
        lz_buffer[ lz_buffer_iterator++ ]               = compressed_data[ compressed_data_offset ];
546
493k
        uncompressed_data[ uncompressed_data_offset++ ] = compressed_data[ compressed_data_offset ];
547
548
493k
        compressed_data_offset++;
549
550
        /* Make sure the lz buffer iterator wraps around
551
         */
552
493k
        lz_buffer_iterator %= 4096;
553
554
493k
        lz_buffer[ lz_buffer_iterator ] = 0;
555
493k
      }
556
172k
      else
557
172k
      {
558
172k
        if( compressed_data_offset > ( compressed_data_size - 2 ) )
559
21
        {
560
21
          libcerror_error_set(
561
21
           error,
562
21
           LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
563
21
           LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
564
21
           "%s: missing compressed data.",
565
21
           function );
566
567
21
          *uncompressed_data_size = 0;
568
569
21
          return( -1 );
570
21
        }
571
172k
        lzfu_reference_data = &( compressed_data[ compressed_data_offset ] );
572
573
172k
        compressed_data_offset += 2;
574
575
172k
        byte_stream_copy_to_uint16_big_endian(
576
172k
         lzfu_reference_data,
577
172k
         reference_offset );
578
579
172k
        reference_size     = ( reference_offset & 0x000f ) + 2;
580
172k
        reference_offset >>= 4;
581
582
172k
        if( ( uncompressed_data_offset + reference_size - 1 ) >= safe_uncompressed_data_size )
583
17
        {
584
17
          libcerror_error_set(
585
17
           error,
586
17
           LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
587
17
           LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
588
17
           "%s: uncompressed data too small.",
589
17
           function );
590
591
17
          *uncompressed_data_size = uncompressed_data_offset + reference_size;
592
593
17
          return( -1 );
594
17
        }
595
1.52M
        for( reference_iterator = 0; reference_iterator < reference_size; reference_iterator++ )
596
1.35M
        {
597
1.35M
          lz_buffer[ lz_buffer_iterator++ ]               = lz_buffer[ reference_offset ];
598
1.35M
          uncompressed_data[ uncompressed_data_offset++ ] = lz_buffer[ reference_offset ];
599
600
1.35M
          reference_offset++;
601
602
          /* Make sure the lz buffer iterator and reference offset wrap around
603
           */
604
1.35M
          lz_buffer_iterator %= 4096;
605
1.35M
          reference_offset   %= 4096;
606
607
1.35M
          lz_buffer[ lz_buffer_iterator ] = 0;
608
1.35M
        }
609
172k
      }
610
665k
    }
611
83.2k
  }
612
67
  *uncompressed_data_size = uncompressed_data_offset;
613
614
67
  return( 1 );
615
110
}
616