<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>187582</bug_id>
          
          <creation_ts>2018-07-12 00:03:34 -0700</creation_ts>
          <short_desc>Image is unexpectedly decoded</short_desc>
          <delta_ts>2018-11-16 05:35:05 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Images</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>191354</dup_id>
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=170432</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Yoshiaki Jitsukawa">yoshiaki.jitsukawa</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cgarcia</cc>
    
    <cc>clopez</cc>
    
    <cc>fujii</cc>
    
    <cc>magomez</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>simon.fraser</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1441433</commentid>
    <comment_count>0</comment_count>
    <who name="Yoshiaki Jitsukawa">yoshiaki.jitsukawa</who>
    <bug_when>2018-07-12 00:03:34 -0700</bug_when>
    <thetext>JavaScript code like
 var img = new Image();
 img.src = &quot;foo.jpg&quot;;
unexpectedly gets the image decoded to a bitmap.

I&apos;ve confirmed that JPEGImageDecoder::decode() was called with onlySize == false, using the GTK port.

The callstack is like as follows (Just a WebCore::Image::isNull() call caused decoding):

 WebCore::JPEGImageDecoder::decode(bool onlySize, bool allDataReceived)
 WebCore::JPEGImageDecoder::frameBufferAtIndex(size_t index)
 WebCore::ScalableImageDecoder::frameIsCompleteAtIndex(size_t index)
 WebCore::ImageSource::cacheMetadataAtIndex(size_t index, enum class
 WebCore::SubsamplingLevel subsamplingLevel, enum class WebCore::DecodingStatus decodingStatus)
 WebCore::ImageSource::frameAtIndexCacheIfNeeded(size_t index, enum class
WebCore::ImageFrame::Caching caching, const std::optional&lt;WebCore::SubsamplingLevel&gt;&amp;
subsamplingLevel)
 WebCore::ImageSource::frameMetadataAtIndexCacheIfNeeded
 WebCore::ImageSource::size()
 WebCore::BitmapImage::size()
 WebCore::Image::isNull()</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1441436</commentid>
    <comment_count>1</comment_count>
    <who name="Yoshiaki Jitsukawa">yoshiaki.jitsukawa</who>
    <bug_when>2018-07-12 00:12:54 -0700</bug_when>
    <thetext>I thought the &quot;return m_decoder-&gt;size();&quot; code would be taken:

IntSize ImageSource::size()
{
#if !USE(CG)
    // It&apos;s possible that we have decoded the metadata, but not frame contents yet. In that case ImageDecoder claims to
    // have the size available, but the frame cache is empty. Return the decoder size without caching in such case.
    if (m_frames.isEmpty() &amp;&amp; isDecoderAvailable())
        return m_decoder-&gt;size();
#endif
    return frameMetadataAtIndexCacheIfNeeded&lt;IntSize&gt;(0, (&amp;ImageFrame::size), &amp;m_size, ImageFrame::Caching::Metadata, SubsamplingLevel::Default);
}

but actually m_frames was not empty because dataChanged() added a frame by
growFrames() when EncodedDataStatus got to SizeAvailable

EncodedDataStatus ImageSource::dataChanged(SharedBuffer* data, bool allDataReceived)
{
    setData(data, allDataReceived);
    clearMetadata();
    EncodedDataStatus status = encodedDataStatus();
    if (status &gt;= EncodedDataStatus::SizeAvailable)
        growFrames();
    return status;
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1479363</commentid>
    <comment_count>2</comment_count>
    <who name="Fujii Hironori">fujii</who>
    <bug_when>2018-11-16 05:35:05 -0800</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 191354 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>