/* We use off_t here because lseek() is declared that way. */
- /* Reduce a request that would overflow the 'seek' variable. */
+ /* Do not perform a seek which cannot be fulfilled. */
if (sizeof(request) > sizeof(seek)) {
const int64_t max_seek =
(((int64_t)1 << (seek_bits - 1)) - 1) * 2 + 1;
const int64_t min_seek = ~max_seek;
- if (request > max_seek)
- seek = (off_t)max_seek;
- else if (request < min_seek)
- seek = (off_t)min_seek;
+ if (request < min_seek || request > max_seek) {
+ errno = EOVERFLOW;
+ goto err;
+ }
}
r = lseek(mine->fd, seek, whence);
if (r >= 0)
return r;
+err:
if (errno == ESPIPE) {
archive_set_error(a, errno,
"A file descriptor(%d) is not seekable(PIPE)", mine->fd);
int seek_bits = sizeof(seek) * 8 - 1;
(void)a; /* UNUSED */
- /* Reduce a request that would overflow the 'seek' variable. */
+ /* Do not perform a seek which cannot be fulfilled. */
if (sizeof(request) > sizeof(seek)) {
const int64_t max_seek =
(((int64_t)1 << (seek_bits - 1)) - 1) * 2 + 1;
const int64_t min_seek = ~max_seek;
- if (request > max_seek)
- seek = max_seek;
- else if (request < min_seek)
- seek = min_seek;
+ if (request < min_seek || request > max_seek) {
+ errno = EOVERFLOW;
+ goto err;
+ }
}
#ifdef __ANDROID__
}
#endif
/* If we arrive here, the input is corrupted or truncated so fail. */
+err:
archive_set_error(a, errno, "Error seeking in FILE* pointer");
return (ARCHIVE_FATAL);
}
/* We use off_t here because lseek() is declared that way. */
- /* Reduce a request that would overflow the 'seek' variable. */
+ /* Do not perform a seek which cannot be fulfilled. */
if (sizeof(request) > sizeof(seek)) {
const int64_t max_seek =
(((int64_t)1 << (seek_bits - 1)) - 1) * 2 + 1;
const int64_t min_seek = ~max_seek;
- if (request > max_seek)
- seek = (off_t)max_seek;
- else if (request < min_seek)
- seek = (off_t)min_seek;
+ if (request < min_seek || request > max_seek) {
+ errno = EOVERFLOW;
+ goto err;
+ }
}
r = lseek(mine->fd, seek, whence);
return r;
/* If the input is corrupted or truncated, fail. */
+err:
if (mine->filename_type == FNT_STDIN)
archive_set_error(a, errno, "Error seeking in stdin");
else if (mine->filename_type == FNT_MBS)