Bug 59477 - Loss of precision errors throughout the codebase spotted by GCC 4.6
Summary: Loss of precision errors throughout the codebase spotted by GCC 4.6
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-26 11:48 PDT by Xan Lopez
Modified: 2011-04-26 16:33 PDT (History)
1 user (show)

See Also:


Attachments
precission.diff (8.03 KB, patch)
2011-04-26 11:54 PDT, Xan Lopez
ap: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Xan Lopez 2011-04-26 11:48:35 PDT
GCC 4.6 seems to be more picky about trying to stuff 64bit values into 32bit variables (as it should!). All the cases seem safe to fix by forcefully casting the value, since it seems either impossible (ByteCodeGenerator, UTF8, ...) or extremely unlikely (the string length in FontGtk) that the value would overflow a 32bit value. At worst, we are not really making things worse, but of course in some cases it might make sense to change the code to not force a cast here.
Comment 1 Xan Lopez 2011-04-26 11:54:27 PDT
Created attachment 91136 [details]
precission.diff
Comment 2 Alexey Proskuryakov 2011-04-26 16:33:11 PDT
Comment on attachment 91136 [details]
precission.diff

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

I think that this should be split into parts that domain experts could look at.

> Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:2102
> +    SwitchInfo info = { static_cast<uint32_t>(instructions().size()), type };

I think that this patch is making things worse in that once this warning is enabled in some other compiler, we won't see the issues. It's not obvious to me that malicious code can't create 4 billion instructions.

> Source/JavaScriptCore/wtf/unicode/UTF8.cpp:236
> +static const UChar32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL, 0x03C82080UL, static_cast<const UChar32>(0xFA082080UL), static_cast<const UChar32>(0x82082080UL) };

Can this be fixed by not using UChar32? These are not Unicode characters, these are magic numbers.

> Source/WebCore/plugins/PluginPackage.cpp:348
> +        static_cast<unsigned int>(m_lastModified)

We don't use "unsigned int", we use "unsigned".