Bug 246406 - [WTF] MediaTime: assert not double in timeValue() and timeScale()
Summary: [WTF] MediaTime: assert not double in timeValue() and timeScale()
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alicia Boya García
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-10-12 09:19 PDT by Alicia Boya García
Modified: 2022-10-19 09:20 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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>