Rizin
unix-like reverse engineering framework and cli tools
zip_source_read.c File Reference
#include "zipint.h"

Go to the source code of this file.

Functions

zip_int64_t zip_source_read (zip_source_t *src, void *data, zip_uint64_t len)
 
bool _zip_source_eof (zip_source_t *src)
 

Function Documentation

◆ _zip_source_eof()

bool _zip_source_eof ( zip_source_t src)

Definition at line 94 of file zip_source_read.c.

94  {
95  return src->eof;
96 }
lzma_index * src
Definition: index.h:567

References src.

Referenced by zip_source_read().

◆ zip_source_read()

zip_int64_t zip_source_read ( zip_source_t src,
void *  data,
zip_uint64_t  len 
)

Definition at line 39 of file zip_source_read.c.

39  {
40  zip_uint64_t bytes_read;
41  zip_int64_t n;
42 
43  if (src->source_closed) {
44  return -1;
45  }
46  if (!ZIP_SOURCE_IS_OPEN_READING(src) || len > ZIP_INT64_MAX || (len > 0 && data == NULL)) {
47  zip_error_set(&src->error, ZIP_ER_INVAL, 0);
48  return -1;
49  }
50 
51  if (src->had_read_error) {
52  return -1;
53  }
54 
55  if (_zip_source_eof(src)) {
56  return 0;
57  }
58 
59  if (len == 0) {
60  return 0;
61  }
62 
63  bytes_read = 0;
64  while (bytes_read < len) {
65  if ((n = _zip_source_call(src, (zip_uint8_t *)data + bytes_read, len - bytes_read, ZIP_SOURCE_READ)) < 0) {
66  src->had_read_error = true;
67  if (bytes_read == 0) {
68  return -1;
69  }
70  else {
71  return (zip_int64_t)bytes_read;
72  }
73  }
74 
75  if (n == 0) {
76  src->eof = 1;
77  break;
78  }
79 
80  bytes_read += (zip_uint64_t)n;
81  }
82 
83  if (src->bytes_read + bytes_read < src->bytes_read) {
84  src->bytes_read = ZIP_UINT64_MAX;
85  }
86  else {
87  src->bytes_read += bytes_read;
88  }
89  return (zip_int64_t)bytes_read;
90 }
size_t len
Definition: 6502dis.c:15
#define NULL
Definition: cris-opc.c:27
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
@ ZIP_SOURCE_READ
Definition: zip.h:221
#define ZIP_ER_INVAL
Definition: zip.h:123
int n
Definition: mipsasm.c:19
zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command)
bool _zip_source_eof(zip_source_t *src)
uint64_t zip_uint64_t
Definition: zipconf.h:39
uint8_t zip_uint8_t
Definition: zipconf.h:33
#define ZIP_UINT64_MAX
Definition: zipconf.h:55
#define ZIP_INT64_MAX
Definition: zipconf.h:54
int64_t zip_int64_t
Definition: zipconf.h:38
#define ZIP_SOURCE_IS_OPEN_READING(src)
Definition: zipint.h:402

References _zip_source_call(), _zip_source_eof(), len, n, NULL, src, ZIP_ER_INVAL, zip_error_set(), ZIP_INT64_MAX, ZIP_SOURCE_IS_OPEN_READING, ZIP_SOURCE_READ, and ZIP_UINT64_MAX.

Referenced by _zip_file_get_end(), _zip_read(), compress_read(), copy_source(), crc_read(), decrypt_header(), main(), pkware_decrypt(), pkware_encrypt(), verify_hmac(), window_read(), winzip_aes_decrypt(), winzip_aes_encrypt(), write_memory_src_to_file(), and zip_fread().