rails-mini-profiler
rails-mini-profiler copied to clipboard
Profiling file upload produces a "string contains null byte" argument error
Issue Summary
Multipart request body when uploading a file contains NULL bytes and the following error occurs when persisting the instance of ProfiledRequest on postgresql.
Rails -- Exception: ArgumentError: string contains null byte
Steps to Reproduce
- Monitor a file upload with rails-mini-profiler
Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?
It should handle this case properly without crashing.
Dirty workaround
config/environments/development.rb:
config.to_prepare do
RailsMiniProfiler::ProfiledRequest.class_eval do
before_save do
self.request_body = request_body.to_s
.encode('UTF-8', invalid: :replace, undef: :replace)
.delete("\000")
end
end
end
Edit: Fix typos
It should handle this case properly without crashing.
I agree :grin:
Thanks for the great description and workaround, really helps with debugging. I'll take a look :+1:
To be exhaustive: Same problem arise when sending binary content in the response (pdf, etc.)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
As mentionned above, the response body should be sanitized too. Should I create a new issue ?
@Qapybara28 My bad, reading is hard. I created a new issue for that, and will tackle that ASAP - unless you want to create a PR yourself :wink:
Thanks a lot for bringing it up! :raised_hands: