aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/liblzma/common/common.c')
-rw-r--r--src/liblzma/common/common.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/liblzma/common/common.c b/src/liblzma/common/common.c
index 10fc8840..8de37d00 100644
--- a/src/liblzma/common/common.c
+++ b/src/liblzma/common/common.c
@@ -289,13 +289,21 @@ lzma_code(lzma_stream *strm, lzma_action action)
strm->next_in, &in_pos, strm->avail_in,
strm->next_out, &out_pos, strm->avail_out, action);
- strm->next_in += in_pos;
- strm->avail_in -= in_pos;
- strm->total_in += in_pos;
+ // Updating next_in and next_out has to be skipped when they are NULL
+ // to avoid null pointer + 0 (undefined behavior). Do this by checking
+ // in_pos > 0 and out_pos > 0 because this way NULL + non-zero (a bug)
+ // will get caught one way or other.
+ if (in_pos > 0) {
+ strm->next_in += in_pos;
+ strm->avail_in -= in_pos;
+ strm->total_in += in_pos;
+ }
- strm->next_out += out_pos;
- strm->avail_out -= out_pos;
- strm->total_out += out_pos;
+ if (out_pos > 0) {
+ strm->next_out += out_pos;
+ strm->avail_out -= out_pos;
+ strm->total_out += out_pos;
+ }
strm->internal->avail_in = strm->avail_in;