diff --git a/stream/stream.c b/stream/stream.c index dd67825dd5..43a7f51a60 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -803,7 +803,7 @@ int stream_skip_bom(struct stream *s) struct bstr stream_read_complete(struct stream *s, void *talloc_ctx, int max_size) { - if (max_size > 1000000000) + if (max_size <= 0 || max_size > STREAM_MAX_READ_SIZE) abort(); int bufsize; diff --git a/stream/stream.h b/stream/stream.h index 423ba12d91..58b55e1a43 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -32,6 +32,9 @@ // it's guaranteed that you can seek back by <= of this size again. #define STREAM_BUFFER_SIZE 2048 +// Maximum size of a complete read. +#define STREAM_MAX_READ_SIZE (INT_MAX - 1) + // flags for stream_open_ext (this includes STREAM_READ and STREAM_WRITE) // stream->mode