<div dir="ltr">Danny, have you considered using random testing to compare the C implementation to the Racket one?<div><br></div><div>You have a great example of a bug to evaluate a random testing strategy!</div><div><br></div>
<div>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 5, 2013 at 6:03 PM, <span dir="ltr"><<a href="mailto:dyoo@racket-lang.org" target="_blank">dyoo@racket-lang.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">dyoo has updated `master' from bf2768f2c5 to c6775cc060.<br>
<a href="http://git.racket-lang.org/plt/bf2768f2c5..c6775cc060" target="_blank">http://git.racket-lang.org/plt/bf2768f2c5..c6775cc060</a><br>
<br>
=====[ 2 Commits ]======================================================<br>
Directory summary:<br>
7.9% collects/file/<br>
92.0% collects/tests/file/<br>
<br>
~~~~~~~~~~<br>
<br>
31b6648 Danny Yoo <<a href="mailto:dyoo@racket-lang.org">dyoo@racket-lang.org</a>> 2013-02-04 23:53<br>
:<br>
| Add test case to show bug with inflate.<br>
|<br>
| related to PR 13489.<br>
:<br>
M collects/tests/file/gzip.rkt | 52 +++++++++++++++++++++++++++++++++++++++++<br>
<br>
~~~~~~~~~~<br>
<br>
c6775cc Danny Yoo <<a href="mailto:dyoo@racket-lang.org">dyoo@racket-lang.org</a>> 2013-02-04 23:45<br>
:<br>
| Fix to inflate: treat EOF as a character, as in the C code.<br>
|<br>
| closes PR 13489.<br>
|<br>
| In the C code, inflate is allowed to peek at least one character<br>
| beyond the extent of a deflated byte sequence. The thread related to<br>
| the bug report of PR 13489 documents that deflate can peek beyond EOF.<br>
:<br>
M collects/file/gunzip.rkt | 3 ++-<br>
<br>
=====[ Overall Diff ]===================================================<br>
<br>
collects/file/gunzip.rkt<br>
~~~~~~~~~~~~~~~~~~~~~~~~<br>
--- OLD/collects/file/gunzip.rkt<br>
+++ NEW/collects/file/gunzip.rkt<br>
@@ -278,7 +278,8 @@<br>
(set! buf-pos MAX-LOOKAHEAD))<br>
(let ([got (peek-bytes-avail! buffer buf-pos #f input-port buf-pos BUFFER-SIZE)])<br>
(if (eof-object? got)<br>
- (error 'inflate "unexpected end of file")<br>
+ (begin (bytes-set! buffer buf-pos 255)<br>
+ (set! buf-max (add1 buf-pos)))<br>
(set! buf-max (+ buf-pos got))))<br>
(READBITS n))<br>
(let ([v (bytes-ref buffer buf-pos)])<br>
<br>
collects/tests/file/gzip.rkt<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
--- OLD/collects/tests/file/gzip.rkt<br>
+++ NEW/collects/tests/file/gzip.rkt<br>
@@ -21,6 +21,56 @@<br>
(test (< (/ o i) ratio))))))<br>
=> buf))<br>
<br>
+<br>
+<br>
+(define (test-degenerate-input-1)<br>
+ ;; The content here causes fails in Racket <= 5.3.2. This test case<br>
+ ;; makes sure it doesn't break now.<br>
+ (define sample-file<br>
+ (bytes-append #"(\"5.3.2\" (\"ab7f6f4533252566bc62383ca395f8272851592b\""<br>
+ #" . \"9364523f1c28f962fb967025aa140670c9b5b9a5\") "<br>
+ #"#\"/Users/dyoo/work/minipascal/minipascal/lang/../semantics.rkt\""<br>
+ #" (collects #\"syntax\" #\"parse\" #\"private\" #\"runtime-report.rkt\")"<br>
+ #" #\"/Users/dyoo/work/minipascal/minipascal/lang/reader.rkt\")\n"))<br>
+<br>
+ (define compressed (open-output-bytes))<br>
+<br>
+ (deflate (open-input-bytes sample-file) compressed)<br>
+<br>
+ (define inflated (open-output-bytes))<br>
+ (define ip (open-input-bytes (get-output-bytes compressed)))<br>
+ (inflate ip inflated)<br>
+<br>
+ (test (get-output-bytes inflated) => sample-file)<br>
+ (test (read-byte ip) => eof))<br>
+<br>
+<br>
+(define (test-degenerate-input-2)<br>
+ ;; Like the first test, but we add a zero byte at the end. We make sure the inflater<br>
+ ;; doesn't consume the extra byte.<br>
+ (define sample-file<br>
+ (bytes-append #"(\"5.3.2\" (\"ab7f6f4533252566bc62383ca395f8272851592b\""<br>
+ #" . \"9364523f1c28f962fb967025aa140670c9b5b9a5\") "<br>
+ #"#\"/Users/dyoo/work/minipascal/minipascal/lang/../semantics.rkt\""<br>
+ #" (collects #\"syntax\" #\"parse\" #\"private\" #\"runtime-report.rkt\")"<br>
+ #" #\"/Users/dyoo/work/minipascal/minipascal/lang/reader.rkt\")\n"))<br>
+<br>
+ (define compressed (open-output-bytes))<br>
+<br>
+ (deflate (open-input-bytes sample-file) compressed)<br>
+<br>
+ (define inflated (open-output-bytes))<br>
+ (define ip (open-input-bytes (bytes-append (get-output-bytes compressed) (bytes 0))))<br>
+ (inflate ip inflated)<br>
+<br>
+ (test (get-output-bytes inflated) => sample-file)<br>
+ (test (read-byte ip) => 0)<br>
+ (test (read-byte ip) => eof))<br>
+<br>
+<br>
+<br>
+<br>
+<br>
(define (test-big-file)<br>
(define big-file<br>
(build-path (collection-path "drracket/private") "unit.rkt"))<br>
@@ -31,6 +81,8 @@<br>
(define (rand-bytes)<br>
(list->bytes (for/list ([j (in-range (random 1000))]) (random 256))))<br>
(test-big-file)<br>
+ (test-degenerate-input-1)<br>
+ (test-degenerate-input-2)<br>
(for ([i (in-range 100)]) (id* (rand-bytes)))<br>
(regression-test))<br>
<br>
</blockquote></div><br></div>