Bug 171602 - REGRESSION(r215686): Incremental reads from SharedBuffer are wrong after r215686
Summary: REGRESSION(r215686): Incremental reads from SharedBuffer are wrong after r215686
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: Gtk, LayoutTestFailure
Depends on:
Blocks:
 
Reported: 2017-05-03 05:36 PDT by Carlos Garcia Campos
Modified: 2017-05-08 09:03 PDT (History)
9 users (show)

See Also:


Attachments
Patch (3.06 KB, patch)
2017-05-03 05:42 PDT, Carlos Garcia Campos
mcatanzaro: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2017-05-03 05:36:42 PDT
In TextTrackLoader::processNewCueData() and PNGImageReader::decode() we changed the patter to read data from a SharedBuffer at a given offset. The new pattern is not correct, because it assumes the whole segment is always read, and the new offset is not correct when that's not the case. This has broken the rendering of png images in the GTK+ port, only the first bytes are correctly decoded and drawn, but not the rest of the image. See for example:

https://build.webkit.org/results/GTK Linux 64-bit Release (Tests)/r216114 (888)/editing/pasteboard/paste-image-using-image-data-diff.png
Comment 1 Carlos Garcia Campos 2017-05-03 05:42:33 PDT
Created attachment 308899 [details]
Patch
Comment 2 Alexey Proskuryakov 2017-05-03 16:59:41 PDT
Comment on attachment 308899 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=308899&action=review

> Source/WebCore/loader/TextTrackLoader.cpp:103
> -        m_cueParser->parseBytes(segment->data() + bytesToSkip, segment->size() - bytesToSkip);
> +        auto bytesToUse = segment->size() - bytesToSkip;
> +        m_cueParser->parseBytes(segment->data() + bytesToSkip, bytesToUse);
>          bytesToSkip = 0;
> -        m_parseOffset += segment->size();
> +        m_parseOffset += bytesToUse;

There doesn't seem to be a test for this part of the patch. What does this fix?
Comment 3 Carlos Garcia Campos 2017-05-03 23:00:39 PDT
(In reply to Alexey Proskuryakov from comment #2)
> Comment on attachment 308899 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=308899&action=review
> 
> > Source/WebCore/loader/TextTrackLoader.cpp:103
> > -        m_cueParser->parseBytes(segment->data() + bytesToSkip, segment->size() - bytesToSkip);
> > +        auto bytesToUse = segment->size() - bytesToSkip;
> > +        m_cueParser->parseBytes(segment->data() + bytesToSkip, bytesToUse);
> >          bytesToSkip = 0;
> > -        m_parseOffset += segment->size();
> > +        m_parseOffset += bytesToUse;
> 
> There doesn't seem to be a test for this part of the patch. What does this
> fix?

I don't even know what TextTrackLoader is, but the pattern to read the data is exactly the same as in PNGEncoder, so this will fail the same way in case of incremental reads where bytesToSkip != 0 in any of the reads. Alex said he was going to add API to SharedBuffer to make it easier to read this way, so this and PNGEncoder will be updated too eventually.
Comment 4 Carlos Garcia Campos 2017-05-03 23:14:46 PDT
Committed r216174: <http://trac.webkit.org/changeset/216174>
Comment 5 Alex Christensen 2017-05-08 09:03:13 PDT
Comment on attachment 308899 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=308899&action=review

>>> Source/WebCore/loader/TextTrackLoader.cpp:103
>>> +        m_parseOffset += bytesToUse;
>> 
>> There doesn't seem to be a test for this part of the patch. What does this fix?
> 
> I don't even know what TextTrackLoader is, but the pattern to read the data is exactly the same as in PNGEncoder, so this will fail the same way in case of incremental reads where bytesToSkip != 0 in any of the reads. Alex said he was going to add API to SharedBuffer to make it easier to read this way, so this and PNGEncoder will be updated too eventually.

To clarify, we shouldn't add API to SharedBuffer to read from a certain offset.  Since we always read entire segments from SharedBuffers, we should stop keeping track of how many bytes we have read and instead keep track of how many segments we have read.  Then we can skip to a segment with a known index instead of iterating all the segments and counting the number of bytes to skip.  This will require new SharedBuffer API, and it will make loading actually make sense.