Coverage Report

Created: 2025-12-05 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libevtx/libevtx/libevtx_byte_stream.c
Line
Count
Source
1
/*
2
 * Byte stream functions
3
 *
4
 * Copyright (C) 2011-2025, 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 <types.h>
24
25
#include "libevtx_byte_stream.h"
26
#include "libevtx_libcerror.h"
27
#include "libevtx_types.h"
28
29
/* Checks if a byte stream is filled with 0-byte values
30
 * Returns 1 if true, 0 if not or -1 on error
31
 */
32
int libevtx_byte_stream_check_for_zero_byte_fill(
33
     const uint8_t *byte_stream,
34
     size_t byte_stream_size,
35
     libcerror_error_t **error )
36
204k
{
37
204k
  libevtx_aligned_t *aligned_byte_stream_index = NULL;
38
204k
  uint8_t *byte_stream_index                   = NULL;
39
204k
  static char *function                        = "libevtx_byte_stream_check_for_zero_byte_fill";
40
41
204k
  if( byte_stream == NULL )
42
0
  {
43
0
    libcerror_error_set(
44
0
     error,
45
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
46
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
47
0
     "%s: invalid byte stream.",
48
0
     function );
49
50
0
    return( -1 );
51
0
  }
52
204k
  if( byte_stream_size > (size_t) SSIZE_MAX )
53
0
  {
54
0
    libcerror_error_set(
55
0
     error,
56
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
57
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
58
0
     "%s: invalid byte stream size value exceeds maximum.",
59
0
     function );
60
61
0
    return( -1 );
62
0
  }
63
204k
  byte_stream_index = (uint8_t *) byte_stream;
64
65
  /* Only optimize for byte stream larger than the alignment
66
   */
67
204k
  if( byte_stream_size > ( 2 * sizeof( libevtx_aligned_t ) ) )
68
204k
  {
69
    /* Align the byte stream index
70
     */
71
205k
    while( ( (intptr_t) byte_stream_index % sizeof( libevtx_aligned_t ) ) != 0 )
72
76.4k
    {
73
76.4k
      if( *byte_stream_index != 0 )
74
76.1k
      {
75
76.1k
        return( 0 );
76
76.1k
      }
77
328
      byte_stream_index += 1;
78
328
      byte_stream_size  -= 1;
79
328
    }
80
128k
    aligned_byte_stream_index = (libevtx_aligned_t *) byte_stream_index;
81
82
1.86M
    while( byte_stream_size > sizeof( libevtx_aligned_t ) )
83
1.86M
    {
84
1.86M
      if( *aligned_byte_stream_index != 0 )
85
128k
      {
86
128k
        return( 0 );
87
128k
      }
88
1.73M
      aligned_byte_stream_index += 1;
89
1.73M
      byte_stream_size          -= sizeof( libevtx_aligned_t );
90
1.73M
    }
91
335
    byte_stream_index = (uint8_t *) aligned_byte_stream_index;
92
335
  }
93
2.48k
  while( byte_stream_size != 0 )
94
2.22k
  {
95
2.22k
    if( *byte_stream_index != 0 )
96
82
    {
97
82
      return( 0 );
98
82
    }
99
2.14k
    byte_stream_index += 1;
100
2.14k
    byte_stream_size  -= 1;
101
2.14k
  }
102
253
  return( 1 );
103
335
}
104