Copilot commented on code in PR #3266:
URL: https://github.com/apache/tika/pull/3266#discussion_r4120928953


##########
tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml:
##########
@@ -6900,6 +6900,19 @@
     <glob pattern="*.ico"/>
   </mime-type>
 
+  <mime-type type="image/x-win-bitmap">
+    <acronym>CUR</acronym>
+    <_comment>Windows Cursor</_comment>
+    <tika:link>https://en.wikipedia.org/wiki/ICO_(file_format)</tika:link>
+    <magic priority="50">
+      <!-- reserved 0, type 2, count below 256 -->
+      <match value="\000\000\002\000" type="string" offset="0">

Review Comment:
   The new CUR MIME type is not added to `InferenceLoader.NON_RASTER` 
(tika-serialization/src/main/java/org/apache/tika/config/loader/InferenceLoader.java:59-62).
 Since `InputKind.of` classifies every `image/*` type as IMAGES, a default 
IMAGES binding will now offer CUR container bytes to an image embedding engine, 
unlike the existing ICO type. Add this type to the default exclusion list or 
provide a supported raster representation.



##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/main/java/org/apache/tika/parser/image/ICOParser.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.image;
+
+import java.io.IOException;
+import java.util.Set;
+
+import org.apache.commons.io.IOUtils;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+import org.apache.tika.annotation.TikaComponent;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.extractor.EmbeddedDocumentUtil;
+import org.apache.tika.io.BoundedInputStream;
+import org.apache.tika.io.EndianUtils;
+import org.apache.tika.io.TikaInputStream;
+import org.apache.tika.metadata.HttpHeaders;
+import org.apache.tika.metadata.Icon;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.TIFF;
+import org.apache.tika.mime.MediaType;
+import org.apache.tika.parser.ParseContext;
+import org.apache.tika.parser.Parser;
+import org.apache.tika.sax.XHTMLContentHandler;
+
+/**
+ * Parser for Windows icon (ICO) and cursor (CUR) files. Reads the ICONDIR
+ * and the header of every image to report the dimensions and colour depth of
+ * the largest image, the list of all images and, for cursors, the hotspot.
+ * The images themselves are not decoded.
+ * <p>
+ * The directory's own width, height and colour fields are unreliable (256 px
+ * is stored as 0, many tools leave the bit count empty), so the values come
+ * from each image's PNG IHDR or BITMAPINFOHEADER and the directory is only
+ * the fallback.
+ */
+@TikaComponent
+public class ICOParser implements Parser {
+
+    private static final long serialVersionUID = 4212837190215395123L;
+
+    static final MediaType ICO_TYPE = MediaType.image("vnd.microsoft.icon");
+    static final MediaType CUR_TYPE = MediaType.image("x-win-bitmap");
+
+    private static final Set<MediaType> SUPPORTED_TYPES = Set.of(ICO_TYPE, 
CUR_TYPE);
+
+    private static final int TYPE_ICON = 1;
+    private static final int TYPE_CURSOR = 2;
+    private static final int HEADER_SIZE = 6;
+    private static final int ENTRY_SIZE = 16;
+    private static final int BITMAP_INFO_HEADER_SIZE = 40;
+    private static final byte[] PNG_SIGNATURE =
+            {(byte) 0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n'};
+    private static final int PNG_IHDR_SIZE = 8 + 8 + 13;
+    // Icons are small; anything bigger is read only this far
+    private static final int MAX_FILE_SIZE = 16 * 1024 * 1024;
+
+    @Override
+    public Set<MediaType> getSupportedTypes(ParseContext context) {
+        return SUPPORTED_TYPES;

Review Comment:
   Claiming the canonical `image/vnd.microsoft.icon` type here changes 
`DefaultParser`'s mapping from `ImageParser` to `ICOParser`. The parser-order 
integration test still compares that type against the 2.4.1 baseline resources, 
which list `ImageParser`, so the test suite will fail until the current 
baseline is updated for this intentional replacement.
   
   This issue also appears in the following locations of the same file:
   - line 81
   - line 102
   - line 143
   - line 153



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to