mime-types / ruby-mime-types

Ruby MIME type registry library
Other
324 stars 122 forks source link

Uncontrolled growth of the type variants or extension index lists #136

Closed halostatue closed 6 years ago

halostatue commented 6 years ago

While investigating #117, #127, and #134, I noticed that the #default_proc usage in MIME::Types::Container could potentially cause uncontrolled growth in memory by the constant querying of unknown types and/or extensions.

MIME::Types::Container was originally a subclass of Hash with a default Proc (->(h, k) { h[k] = Set.new }) and some methods to assist with JSON/YAML encoding and Marshal support (because the presence of the default_proc breaks those things or is missing on restoration).

This particular implementation is extremely useful during construction, because it allowed for the simplification of a number of call-sites, but it had the unintended consequence of recording every missed query and adding an empty (but mutable) Set during normal (and much more frequent) execution.