Re: [PATCH] mod_deflate: hardcoded "%ld" -> APR_OFF_T_FMT

2018-12-16 Thread Yann Ylavic
On Sun, Dec 16, 2018 at 2:21 PM Yann Ylavic  wrote:
>
> On Sun, Dec 16, 2018 at 2:14 PM Stefan Sperling  wrote:
> >
> > The file /usr/include/zlib.h I have on OpenBSD -current has this:
> >
> > typedef struct z_stream_s {
> > [...]
> > z_off_t  total_in;  /* total nb of input bytes read so far */
> > [...]
> > z_off_t  total_out; /* total nb of bytes output so far */
> > [...]
> > } z_stream;
>
> Ouch.
>
> >
> > This looks like an OpenBSD-specific change though (diff below).
> > I guess this will force OpenBSD to carry a local patch for
> > mod_deflate then, or just compile without -Werror.
>
> I think we need a bit of #ifdef-ery in mod_deflate then, a BSD only
> fix wouldn't help those who build from sources.
>
> Do you know which BSD(s) are concerned (if not all)?

Since it's logging only, it may be easier to cast to (long) each
total_in/out though.


Re: [PATCH] mod_deflate: hardcoded "%ld" -> APR_OFF_T_FMT

2018-12-16 Thread Yann Ylavic
On Sun, Dec 16, 2018 at 2:14 PM Stefan Sperling  wrote:
>
> The file /usr/include/zlib.h I have on OpenBSD -current has this:
>
> typedef struct z_stream_s {
> [...]
> z_off_t  total_in;  /* total nb of input bytes read so far */
> [...]
> z_off_t  total_out; /* total nb of bytes output so far */
> [...]
> } z_stream;

Ouch.

>
> This looks like an OpenBSD-specific change though (diff below).
> I guess this will force OpenBSD to carry a local patch for
> mod_deflate then, or just compile without -Werror.

I think we need a bit of #ifdef-ery in mod_deflate then, a BSD only
fix wouldn't help those who build from sources.

Do you know which BSD(s) are concerned (if not all)?


Re: [PATCH] mod_deflate: hardcoded "%ld" -> APR_OFF_T_FMT

2018-12-16 Thread Stefan Sperling
On Sun, Dec 16, 2018 at 02:03:45PM +0100, Yann Ylavic wrote:
> On Sun, Dec 16, 2018 at 1:28 PM Stefan Sperling  wrote:
> >
> > mod_deflates hard-codes some off_t format directives to "%ld".
> > It seems to me this code should use the macro provided by APR instead.
> >
> > Looking for another pair of eyes. Does this patch look good to commit?
> 
> It seems that zlib defines total_in/out as uLong, i.e.:
> typedef struct z_stream_s {
> [...]
> uLongtotal_in;  /* total number of input bytes read so far */
> [...]
> uLongtotal_out; /* total number of bytes output so far */
> [...]
> } z_stream;
> 
> So %ld (or %lu) looks correct to me.
> 
> (mod_brotli uses apr_off_t for them but it's an internal struct there).
> 
> Regards,
> Yann.

Thanks for checking. This seems to depend on the version of zlib.
The file /usr/include/zlib.h I have on OpenBSD -current has this:

typedef struct z_stream_s {
[...]
z_off_t  total_in;  /* total nb of input bytes read so far */
[...]
z_off_t  total_out; /* total nb of bytes output so far */
[...]
} z_stream;

And the compiler (clang) now rightly complains as follows:

/home/stsp/svn/src/httpd-2.4.37/modules/filters/mod_deflate.c:856:27: error:   
  format specifies type 'long' but the argument has type 'off_t'   
  (aka 'long long') [-Werror,-Wformat] 
  ctx->stream.total_in, ctx->stream.total_out, r->uri);
  ^~~~ 
/home/stsp/svn/src/httpd-2.4.37/modules/filters/mod_deflate.c:856:49: error:   
  format specifies type 'long' but the argument has type 'off_t'   
  (aka 'long long') [-Werror,-Wformat] 
  ctx->stream.total_in, ctx->stream.total_out, r->uri);
^  
/home/stsp/svn/src/httpd-2.4.37/modules/filters/mod_deflate.c:1423:31: error:  
  format specifies type 'long' but the argument has type 'off_t'   
  (aka 'long long') [-Werror,-Wformat] 
  ctx->stream.total_in, ctx->stream.total_out, 
  ^~~~ 
/home/stsp/svn/src/httpd-2.4.37/modules/filters/mod_deflate.c:1423:53: error:  
  format specifies type 'long' but the argument has type 'off_t'   
  (aka 'long long') [-Werror,-Wformat] 
  ctx->stream.total_in, ctx->stream.total_out, 
^  
/home/stsp/svn/src/httpd-2.4.37/modules/filters/mod_deflate.c:1450:39: error:  
  format specifies type 'long' but the argument has type 'off_t'   
  (aka 'long long') [-Werror,-Wformat] 
  ctx->stream.total_out, compLen); 
  ^
/home/stsp/svn/src/httpd-2.4.37/modules/filters/mod_deflate.c:1626:27: error:  
  format specifies type 'long' but the argument has type 'off_t'   
  (aka 'long long') [-Werror,-Wformat] 
  ctx->stream.total_in, ctx->stream.total_out, r->uri);
  ^~~~ 
/home/stsp/svn/src/httpd-2.4.37/modules/filters/mod_deflate.c:1626:49: error:  
  format specifies type 'long' but the argument has type 'off_t'   
  (aka 'long long') [-Werror,-Wformat] 
  ctx->stream.total_in, ctx->stream.total_out, r->uri);
^  
7 errors generated.

This looks like an OpenBSD-specific change though (diff below).
I guess this will force OpenBSD to carry a local patch for
mod_deflate then, or just compile without -Werror.

RCS file: /cvs/src/lib/libz/zlib.h,v
Working file: zlib.h
head: 1.10
[...]

revision 1.7
date: 2003/12/16 22:35:50;  author: henning;  state: Exp;  lines: +2 -2;
total_in and total_out need to be off_t, not unsigned long.
some bugs return: i fixed the same some months ago when we had this other gzip
there.
this bug resulted in wrong size stats for > 4GB files, and in the case
that the input file was > 4GB and could be compressed to < 4GB gzip
not zipping it as it would grow in its eyes.
=

Index: zlib.h
===
RCS file: /cvs/src/lib/libz/zlib.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -p -r1.6 -r1.7
--- zlib.h  16 Dec 2003 22:33:02 -  

Re: [PATCH] mod_deflate: hardcoded "%ld" -> APR_OFF_T_FMT

2018-12-16 Thread Yann Ylavic
On Sun, Dec 16, 2018 at 1:28 PM Stefan Sperling  wrote:
>
> mod_deflates hard-codes some off_t format directives to "%ld".
> It seems to me this code should use the macro provided by APR instead.
>
> Looking for another pair of eyes. Does this patch look good to commit?

It seems that zlib defines total_in/out as uLong, i.e.:
typedef struct z_stream_s {
[...]
uLongtotal_in;  /* total number of input bytes read so far */
[...]
uLongtotal_out; /* total number of bytes output so far */
[...]
} z_stream;

So %ld (or %lu) looks correct to me.

(mod_brotli uses apr_off_t for them but it's an internal struct there).

Regards,
Yann.


[PATCH] mod_deflate: hardcoded "%ld" -> APR_OFF_T_FMT

2018-12-16 Thread Stefan Sperling
mod_deflates hard-codes some off_t format directives to "%ld".
It seems to me this code should use the macro provided by APR instead.

Looking for another pair of eyes. Does this patch look good to commit?

Index: modules/filters/mod_deflate.c
===
--- modules/filters/mod_deflate.c   (revision 1849023)
+++ modules/filters/mod_deflate.c   (working copy)
@@ -893,7 +893,8 @@ static apr_status_t deflate_out_filter(ap_filter_t
f->c->bucket_alloc);
 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01384)
-  "Zlib: Compressed %ld to %ld : URL %s",
+  "Zlib: Compressed %" APR_OFF_T_FMT
+ " to %" APR_OFF_T_FMT " : URL %s",
   ctx->stream.total_in, ctx->stream.total_out, r->uri);
 
 /* leave notes for logging */
@@ -1438,7 +1439,8 @@ static apr_status_t deflate_in_filter(ap_filter_t
 ctx->validation_buffer_length += valid;
 
 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01393)
-  "Zlib: Inflated %ld to %ld : URL %s",
+  "Zlib: Inflated %" APR_OFF_T_FMT
+ " to %" APR_OFF_T_FMT " : URL %s",
   ctx->stream.total_in, ctx->stream.total_out,
   r->uri);
 
@@ -1459,7 +1461,8 @@ static apr_status_t deflate_in_filter(ap_filter_t
 if ((ctx->stream.total_out & 0x) != compLen) {
 inflateEnd(>stream);
 ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, 
APLOGNO(01395)
-  "Zlib: Length %ld of inflated data does "
+  "Zlib: Length %" APR_OFF_T_FMT
+ " of inflated data does "
   "not match expected value %ld",
   ctx->stream.total_out, compLen);
 return APR_EGENERAL;
@@ -1628,7 +1631,8 @@ static apr_status_t inflate_out_filter(ap_filter_t
  */
 flush_libz_buffer(ctx, c, inflate, Z_SYNC_FLUSH, UPDATE_CRC);
 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01398)
-  "Zlib: Inflated %ld to %ld : URL %s",
+  "Zlib: Inflated %" APR_OFF_T_FMT
+ " to %" APR_OFF_T_FMT " : URL %s",
   ctx->stream.total_in, ctx->stream.total_out, r->uri);
 
 if (ctx->validation_buffer_length == VALIDATION_SIZE) {