diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl
index 1a8003f..57f369f 100644
--- a/ext/unicorn_http/unicorn_http.rl
+++ b/ext/unicorn_http/unicorn_http.rl
@@ -924,7 +924,18 @@ static VALUE HttpParser_filter_body(VALUE self, VALUE dst, VALUE src)
       assert(hp->s.dest_offset <= hp->offset &&
              "destination buffer overflow");
       advance_str(src, hp->offset);
-      rb_str_set_len(dst, hp->s.dest_offset);
+
+      if (0) {
+        /*
+         * the following should work, but raises:
+         *  can't set length of shared string (RuntimeError)
+         */
+        rb_str_modify(dst);
+        rb_str_set_len(dst, hp->s.dest_offset);
+      } else {
+        /* this does not raise */
+        rb_str_resize(dst, hp->s.dest_offset);
+      }
 
       if (RSTRING_LEN(dst) == 0 && chunked_eof(hp)) {
         assert(hp->len.chunk == 0 && "chunk at EOF but more to parse");
