Bug 246406

Summary: [WTF] MediaTime: assert not double in timeValue() and timeScale()
Product: WebKit Reporter: Alicia Boya García <aboya>
Component: Web Template FrameworkAssignee: Alicia Boya García <aboya>
Status: NEW ---    
Severity: Normal CC: webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Description Alicia Boya García 2022-10-12 09:19:06 PDT
A MediaTime can either represent a time as a fraction or as a floating
point number.

Both representations are stored in a union, with a tag in m_timeFlags to
know which one must be used.

timeValue() and timeScale() are the methods used to get the numerator
and denominator of the time when a MediaTime is fractional. However, as
the code stood before this patch, there is no check (even in Debug mode)
to assert this is the case. An accidental use of timeValue() in this
situation would return an int64_t with the bit contents of an IEEE 754
double, which could cause a hard to debug bug. Similarly, timeScale() is
undefined in this case.

This code adds an assert to both methods to guard against accidental
usages on MediaTime instances containing floating point values.

Additionally: these functions used to return references. Doing so
exposes implementation details of MediaTime and would enable dangerous
and confusing uses (e.g. calling timeValue() first, saving it in a
reference variable, updating the MediaTime and checking the variable
afterwards). All existing uses are as an immediate, so they can be
safely refactored to return by value, which is safer.

* Source/WTF/wtf/MediaTime.h:
Comment 1 Alicia Boya García 2022-10-19 03:16:11 PDT
Pull request: https://github.com/WebKit/WebKit/pull/5533
Comment 2 Radar WebKit Bug Importer 2022-10-19 09:20:38 PDT
<rdar://problem/101340439>