Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undesirable mutation of Marcel::TYPE_EXTS on processing content_type validation #356

Closed
atcruice opened this issue Jan 31, 2025 · 4 comments · Fixed by #357
Closed

Undesirable mutation of Marcel::TYPE_EXTS on processing content_type validation #356

atcruice opened this issue Jan 31, 2025 · 4 comments · Fixed by #357
Assignees
Labels
bug Something isn't working

Comments

@atcruice
Copy link

.each_with_object(Marcel::TYPE_EXTS) { |(k,v), h| h[k] = v unless h.key?(k) }
is mutating the contents of the Marcel::TYPE_EXTS constant.

Additional contents of Marcel::TYPE_EXTS after loading a file containing a content_type validation

diff --git a/Marcel_TYPE_EXTS_before.rb b/Marcel_TYPE_EXTS_after.rb
index c9931865de..df35275b9b 100644
--- a/Marcel_TYPE_EXTS_before.rb
+++ b/Marcel_TYPE_EXTS_after.rb
@@ -905,4 +905,105 @@
   "text/xml"=>[],
   "video/theora"=>[],
   "inode/x-empty"=>["empty"],
+  "application/x-ms-owner"=>nil,
+  "application/x-bplist"=>nil,
+  "application/x-ms-nls"=>nil,
+  "application/vnd.ms-excel.sheet.2"=>nil,
+  "application/vnd.ms-excel.sheet.3"=>nil,
+  "application/vnd.ms-excel.sheet.4"=>nil,
+  "application/vnd.ms-excel.workspace.3"=>nil,
+  "application/vnd.ms-excel.workspace.4"=>nil,
+  "application/x-berkeley-db;format=btree;version=2"=>nil,
+  "application/x-berkeley-db;format=btree;version=3"=>nil,
+  "application/x-berkeley-db;format=btree;version=4"=>nil,
+  "application/x-berkeley-db;format=hash;version=2"=>nil,
+  "application/x-berkeley-db;format=hash;version=3"=>nil,
+  "application/x-berkeley-db;format=hash;version=4"=>nil,
+  "application/x-berkeley-db;format=hash;version=5"=>nil,
+  "application/x-msdownload;format=pe-arm7"=>nil,
+  "application/x-msdownload;format=pe-armLE"=>nil,
+  "application/x-msdownload;format=pe-itanium"=>nil,
+  "application/x-msdownload;format=pe32"=>nil,
+  "application/x-msdownload;format=pe64"=>nil,
+  "application/x-rar-compressed;version=4"=>nil,
+  "application/x-rar-compressed;version=5"=>nil,
+  "application/x-stata-dta;version=10"=>nil,
+  "application/x-stata-dta;version=12"=>nil,
+  "application/x-stata-dta;version=13"=>nil,
+  "application/x-stata-dta;version=14"=>nil,
+  "application/x-stata-dta;version=8"=>nil,
+  "audio/x-oggflac"=>nil,
+  "audio/x-oggpcm"=>nil,
+  "image/heic-sequence"=>nil,
+  "image/heif-sequence"=>nil,
+  "message/news"=>nil,
+  "model/vnd.dwf;version=2"=>nil,
+  "model/vnd.dwf;version=5"=>nil,
+  "model/vnd.dwf;version=6"=>nil,
+  "video/daala"=>nil,
+  "video/x-oggrgb"=>nil,
+  "video/x-ogguvs"=>nil,
+  "video/x-oggyuv"=>nil,
+  "application/x-msdownload;format=pe"=>nil,
+  "application/applefile"=>nil,
+  "application/dicom"=>nil,
+  "application/msword2"=>nil,
+  "application/msword5"=>nil,
+  "application/sereal;version=1"=>nil,
+  "application/sereal;version=2"=>nil,
+  "application/sereal;version=3"=>nil,
+  "application/vnd.digilite.prolights"=>nil,
+  "application/vnd.lotus-1-2-3;version=1"=>nil,
+  "application/vnd.ms-tnef"=>nil,
+  "application/vnd.wordperfect;version=4.2"=>nil,
+  "application/vnd.wordperfect;version=5.0"=>nil,
+  "application/vnd.wordperfect;version=5.1"=>nil,
+  "application/vnd.wordperfect;version=6.x"=>nil,
+  "application/x-berkeley-db;format=btree"=>nil,
+  "application/x-berkeley-db;format=hash"=>nil,
+  "application/x-berkeley-db;format=log"=>nil,
+  "application/x-berkeley-db;format=queue"=>nil,
+  "application/x-coredump"=>nil,
+  "application/x-elf"=>nil,
+  "application/x-executable"=>nil,
+  "application/x-foxmail"=>nil,
+  "application/x-hwp"=>nil,
+  "application/x-isatab"=>nil,
+  "application/x-isatab-assay"=>nil,
+  "application/x-isatab-investigation"=>nil,
+  "application/x-kdelnk"=>nil,
+  "application/x-lha"=>nil,
+  "application/x-lharc"=>nil,
+  "application/x-object"=>nil,
+  "application/x-ole-storage"=>nil,
+  "application/x-sc"=>nil,
+  "application/x-sharedlib"=>nil,
+  "application/x-sqlite3"=>nil,
+  "application/x-tika-ooxml"=>nil,
+  "application/x-vhd"=>nil,
+  "application/x-x509-dsa-parameters"=>nil,
+  "application/x-x509-ec-parameters"=>nil,
+  "application/x-x509-key;format=pem"=>nil,
+  "audio/amr-wb"=>nil,
+  "audio/eac3"=>nil,
+  "audio/prs.sid"=>nil,
+  "audio/webm"=>nil,
+  "image/fits"=>nil,
+  "image/vnd.dxf;format=ascii"=>nil,
+  "image/vnd.dxf;format=binary"=>nil,
+  "image/x-jp2-container"=>nil,
+  "image/x-niff"=>nil,
+  "multipart/appledouble"=>nil,
+  "text/x-matlab"=>nil,
+  "application/zlib"=>nil,
+  "application/x-matroska"=>nil,
+  "application/x-mysql-misam-index"=>nil,
+  "application/x-mysql-table-definition"=>nil,
+  "application/x-tika-msoffice"=>nil,
+  "application/x-x509-key;format=der"=>nil,
+  "application/inf"=>nil,
+  "audio/x-adpcm"=>nil,
+  "audio/x-dec-adpcm"=>nil,
+  "audio/x-dec-basic"=>nil,
+  "text/x-makefile"=>nil,
 }

Looking at how all_available_marcel_content_types is used, I reckon something like the following code might suit, without mutating Marcel's constant.

def all_available_marcel_content_types
  @all_available_marcel_content_types ||= Marcel::TYPE_EXTS
    .keys
    .push(*Marcel::MAGIC.map(&:first))
    .tap(&:uniq!)
end
@Mth0158 Mth0158 added the bug Something isn't working label Jan 31, 2025
@Mth0158 Mth0158 self-assigned this Jan 31, 2025
Mth0158 added a commit that referenced this issue Jan 31, 2025
@Mth0158
Copy link
Collaborator

Mth0158 commented Jan 31, 2025

@atcruice you are totally right, I was a bit hasty with this fix. It should be fixed in the 2.0.2 release that will be live today / tomorrow (and is already present on master if you want to use it straight away).

Mth0158 added a commit that referenced this issue Jan 31, 2025
…of-marceltype_exts-on-processing-content_type-validation

[Validator] Fix issue with all_available_marcel_content_types mutating Marcel::TYPE_EXTS (#356)
@Mth0158 Mth0158 reopened this Jan 31, 2025
@Mth0158
Copy link
Collaborator

Mth0158 commented Jan 31, 2025

(reopened until released)

@Mth0158
Copy link
Collaborator

Mth0158 commented Feb 2, 2025

Released with 2.0.2 :)

@Mth0158 Mth0158 closed this as completed Feb 2, 2025
@atcruice
Copy link
Author

atcruice commented Feb 2, 2025

@Mth0158, thank you for resolving so promptly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants