Integer overflow: Difference between revisions

Content deleted Content added
Methods to address integer overflow problems: language)|C#]] || colspan="2" | modulo power of 2 in unchecked context; <code>System.OverflowException</code> is raised in checked context<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/khy08726.aspx |title=Checked and Unchecked (C# Reference) |last=BillWagner |website=msdn.microsoft.com|date=8 April 2023 }}</ref> |- | Java || modulo power
Tags: Reverted references removed Mobile edit Mobile web edit
Bender the Bot (talk | contribs)
 
(39 intermediate revisions by 17 users not shown)
Line 2:
{{Use American English|date=January 2019}}
 
[[File:Odometer rollover.jpg|thumb|250pxupright=1.3|Integer overflow can be demonstrated through an [[odometer]] overflowing, a mechanical version of the phenomenon. All digits are set to the maximum 9 and the next increment of the white digit causes a cascade of carry-over additions setting all digits to 0, but there is no higher digit (1,000,000s digit) to change to a 1, so the counter resets to zero. This is ''wrapping'' in contrast to ''saturating''.]]
 
In [[computer programming]], an '''integer overflow''' occurs when an [[arithmetic]] operation on integers attempts to create a numeric value that is outside of the range that can be represented with a given number of digits – either higher than the maximum or lower than the minimum representable value.
representable value.
 
Integer overflow specifies an overflow of the [[data type]] [[Integer (computer science)|integer]]. An overflow (of any type) occurs when a [[computer program]] or system tries to store more data in a fixed-size ___location than it can handle, resulting in [[data loss]] or [[Data corruption|corruption]].<ref>{{cite web|url=https://www.lenovo.com/us/en/glossary/overflow-error |title=What is an overflow error?}}</ref> The most common implementation of integers in modern computers are [[two's complement]].<ref>E.g. "Signed integers are two's complement binary values that can be used to represent both positive and negative integer values", Section 4.2.1 in ''Intel 64 and IA-32 Architectures Software Developer's Manual'', Volume 1: Basic Architecture, November 2006</ref> In two's complement the [[Bit numbering#Most_significant_bit|most significant bit]] represents the [[Sign bit|sign]] (positive or negative), and the remaining [[Bit numbering#Signed_integer_example|least significant bits]] represent the number. Unfortunately, for most [[Computer architecture|architectures]] the [[Arithmetic logic unit|ALU]] doesn't know the [[Binary number|binary representation]] is [[Signedness|signed]]. [[Two's_complement#Arithmetic_operations|Arithmetic operations]] can result in a value of bits exceeding the fixed-size of bits representing the number, this causes the sign bit to be changed, an integer overflow. The most infamous examples are: [[2,147,483,647#In_computing|2,147,483,647]] + 1 = -2,147,483,648 and [[32-bit computing#Range_for_storing_integers|-2,147,483,648]] - 1 = 2,147,483,647.
The most common result of an overflow is that the least significant representable digits of the result are stored; the result is said to ''wrap'' around the maximum (i.e. [[Modular arithmetic|modulo]] a power of the [[radix]], usually two in modern computers, but sometimes ten or other number). On some processors like [[give results leading to unintended behavior. In particular, if the possibility has not been anticipated, overflow can compromise a program's reliability and [[software security|security]].
 
On some processors like [[graphics processing unit]]s (GPUs) and [[digital signal processor]]s (DSPs) which support [[saturation arithmetic]], overflowed results would be ''clamped'', i.e. set to the minimum value in the representable range if the result is below the minimum and set to the maximum value in the representable range if the result is above the maximum, rather than wrapped around.
 
An overflow condition may give results leading to unintended behavior. In particular, if the possibility has not been anticipated, overflow can compromise a program's reliability and [[software security|security]].
 
For some applications, such as timers and clocks, wrapping on overflow can be desirable. The [[C11 (C standard revision)|C11 standard]] states that for unsigned integers, modulo wrapping is the defined behavior and the term overflow never applies: "a computation involving unsigned operands can never overflow."<ref name="auto">{{cite web |url=https://webstore.ansi.org/RecordDetail.aspx?sku=ISO/IEC+9899:2011 |title=ISO/IEC 9899:2011 Information technology - Programming languages - C |author=ISO staff |website=ANSI.org}}</ref>
 
== Origin ==
Integer overflow occurs when an [[arithmetic]] operation on integers attempts to create a numeric value that is outside of the range that can be represented with a given number of digits. In the context of computer programming, the integers are [[Binary numeral system|binary]], but any [[Positional notation|positional]] [[numeral system]] can have an invalid result of an arithmetic operation if positions are confined. As shown in the odometer example, using the [[decimal]] system, with the constraint of 6 positions ([[Numerical digit|digits]]) the following operation will have an invalid result: {{math|999999 + 1}}. Likewise, a binary system limited to 4 positions ([[bit|bits]]) will have an invalid result for the following operation: {{code|1111 + 1}}. For both examples the results will have a value exceeding the range that can be represented by the constraints. Another way to look at this problem is that the [[Significant figures|most significant]] position's operation has a [[Carry (arithmetic)|carry]] requiring another position/digit/bit to be allocated, breaking the constraints.
The [[register width]] of a processor determines the range of values that can be represented in its registers. Though the vast majority of computers can perform multiple-precision arithmetic on operands in memory, allowing numbers to be arbitrarily long and overflow to be avoided, the register width limits the sizes of numbers that can be operated on (e.g., added or subtracted) using a single [[Instruction set architecture#Instructions|instruction]] per operation. Typical [[Binary numeral system|binary]] register widths for unsigned integers include:
 
* [[4-bit computing|4-bit]]: maximum representable value 2<sup>4</sup> − 1 = 15
All integers in computer programming have constraints of a max value and min value. The primary factors for determining the range is the allocation of bits and if it is [[Signedness|signed or unsigned]]. The [[Integer (computer science)#Standard_integer|standard integer]] depends on the [[Computing platform|platform]] and [[programming language]]. Additional integer representation can be less than or greater than standard. Examples are the [[Integer (computer science)#Short_integer|short integer]] and [[Integer (computer science)#Long_integer|long integer]] respectively. Even [[Arbitrary-precision arithmetic|arbitrary-precision]] exists, but would be limited by [[Arbitrary-precision arithmetic#Pre-set_precision|pre-set precision]] or available system memory.
* [[8-bit computing|8-bit]]: maximum representable value 2<sup>8</sup> − 1 = 255
 
* [[16-bit computing|16-bit]]: maximum representable value 2<sup>16</sup> − 1 = 65,535
Most [[Arithmetic logic unit|ALUs]] perform operations on [[Signedness|unsigned]] (positive) [[Binary number|binary numbers]]. These ALUs do not have any capability of dealing with [[Signedness|signed]] (positive and negative) numbers. Because most numbers in programs need to support negative numbers, an abstraction is used, redefining the bits' meaning to include a sign. The most common solution is [[two's complement]]. Most programming languages provide this construct. A signed 32-bit integer will use the [[Bit numbering#Most_significant_bit|most significant bit]] to signify the [[Sign bit|sign]] (positive or negative), and the remaining [[Bit numbering#Signed_integer_example|31-bits]] to represent the number. When an [[Two's_complement#Arithmetic_operations|operation]] occurs that results in a [[Carry (arithmetic)|carry]] past the 31-bits allocated for the number, the sign bit is overwritten. The ALU doesn't know it did anything wrong. It is up to the program to detect this overflow fault.
* [[32-bit computing|32-bit]]: maximum representable value 2<sup>32</sup> − 1 = 4,294,967,295 (the most common width for personal computers {{as of|2005|lc=on}}),
 
* [[64-bit computing|64-bit]]: maximum representable value 2<sup>64</sup> − 1 = 18,446,744,073,709,551,615 (the most common width for personal computer [[central processing unit]]s (CPUs), {{as of|2024|lc=on}}),
For usage of unsigned integers of [[register width]], the ALU is not capable of returning a result with more bits outside its width. The ALU will return the result along with a flag for carry-out. When these flags are returned true, the ALU has detected overflow.
* [[128-bit computing|128-bit]]: maximum representable value 2<sup>128</sup> − 1 = 340,282,366,920,938,463,463,374,607,431,768,211,455
 
After overflow is detected, it is up to the program to handle this with additional logic. The resulting value from the operation is [[Data corruption|corrupted]] and can cause additional issues if not handled properly.
 
Using integers of the same size as the [[Arithmetic logic unit|ALU]]'s [[register width]] will have the best performance in most applications. [[Single instruction, multiple data|SIMD]] [[Instruction set architecture|instruction]] extensions can provide single operations for integers exceeding the register width. For [[x86]] [[32-bit computing|32-bit processors]] the [[Streaming SIMD extensions]] (SSE2) added registers for 64-bit integers. For [[x86-64]] [[64-bit computing|64-bit processors]] the [[Advanced Vector Extensions]] (AVX) added registers up to 512-bit integers.<ref>{{cite web|url=https://www.intel.com/content/www/us/en/content-details/812656/intel-avx-512-fast-modular-multiplication-technique-technology-guide.html|title=Intel® AVX-512 - Fast Modular Multiplication Technique}}</ref>
 
{{Table alignment}}
{| class="wikitable defaultright"
|+ Typical Integer Boundaries
|-
! Bits !! Alias{{efn|name=alias}} !! Range !! Signed Range{{efn|name=signed}} !! Unsigned Range
|-
! rowspan="2" style="white-space: preserve nowrap; text-align:center;" | [[8-bit computing|8-bit]]
| rowspan="2" style="text-align:center;" | [[byte]]<ref name="byte">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.byte|title=.NET Byte Struct }}</ref>{{efn|name=byte}}, sbyte,<ref name="sbyte">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.sbyte|title=.NET SByte Struct }}</ref> [[octet (computing)|octet]]
| rowspan="2" style="white-space: preserve nowrap; text-align:center;" | 2<sup>8</sup> − 1 || {{small|-128<ref name="sbyte.min">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.minvalue |title=.NET SByte.MinValue Field }}</ref>}} || {{small|0<ref name="byte.min">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.byte.minvalue |title=.NET Byte.MinValue Field }}</ref>}}
|-
|-
| {{small|127<ref name="sbyte.max">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.sbyte.maxvalue |title=.NET SByte.MaxValue Field }}</ref>}} || {{small|[[255 (number)#In_computing|255]]<ref name="byte.max">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.byte.maxvalue |title=.NET Byte.MaxValue Field }}</ref>}}
|-
|-
! rowspan="2" style="white-space: preserve nowrap; text-align:center;" | [[16-bit computing|16-bit]]
| rowspan="2" style="text-align:center;" | [[Word (data type)|word]], [[Integer (computer science)#Short_integer|short]], int16,<ref name="int16">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.int16|title=.NET Int16 Struct }}</ref> uint16<ref name="uint16">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.uint16|title=.NET UInt16 Struct }}</ref>
| rowspan="2" style="white-space: preserve nowrap; text-align:center;" | 2<sup>16</sup> − 1 || {{small|−32,768<ref name="int16.min">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.int16.minvalue |title=.NET Int16.MinValue Field }}</ref>}} || {{small|0<ref name="uint16.min">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.uint16.minvalue |title=.NET UInt16.MinValue Field }}</ref>}}
|-
|-
| {{small|32,767<ref name="int16.max">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.int16.maxvalue |title=.NET Int16.MaxValue Field }}</ref>}} || {{small|[[65,535#In_computing|65,535]]<ref name="uint16.max">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.uint16.maxvalue |title=.NET UInt16.MaxValue Field }}</ref>}}
|-
|-
! rowspan="2" style="white-space: preserve nowrap; text-align:center;" | [[32-bit computing|32-bit]]{{efn|name=common2005}}
| rowspan="2" style="white-space: preserve nowrap; text-align:center;" | int32,<ref name="int32">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.int32|title=.NET Int32 Struct }}</ref> uint32<ref name="uint32">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.uint32|title=.NET UInt32 Struct }}</ref>
| rowspan="2" style="white-space: preserve nowrap; text-align:center;" | 2<sup>32</sup> − 1 || {{small|[[32-bit computing#Range_for_storing_integers|-2,147,483,648]]<ref name="int32.min">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.int32.minvalue |title=.NET Int32.MinValue Field }}</ref>}} || {{small|0<ref name="uint32.min">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.uint32.minvalue |title=.NET UInt32.MinValue Field }}</ref>}}
|-
|-
| {{small|[[2,147,483,647]]<ref name="int32.max">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.int32.maxvalue |title=.NET Int32.MaxValue Field }}</ref>}} || {{small|[[4,294,967,295#In_computing|4,294,967,295]]<ref name="uint32.max">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.uint32.maxvalue |title=.NET UInt32.MaxValue Field }}</ref>}}
|-
|-
! rowspan="2" style="white-space: preserve nowrap; text-align:center;" | [[64-bit computing|64-bit]]{{efn|name=common2025}}
| rowspan="2" style="white-space: preserve nowrap; text-align:center;" | int64,<ref name="int64">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.int64|title=.NET Int64 Struct }}</ref> uint64<ref name="uint64">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.uint64|title=.NET UInt64 Struct }}</ref>
| rowspan="2" style="white-space: preserve nowrap; text-align:center;" | 2<sup>64</sup> − 1 || {{small|−9,223,372,036,854,775,808<ref name="int64.min">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.int64.minvalue |title=.NET Int64.MinValue Field }}</ref>}} || {{small|0<ref name="uint64.min">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.uint64.minvalue |title=.NET UInt64.MinValue Field }}</ref>}}
|-
|-
| {{small|[[Power of two#2^63-1|9,223,372,036,854,775,807]]<ref name="int64.max">
{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.int64.maxvalue |title=.NET Int64.MaxValue Field }}
</ref>}} || {{small|[[Power of two#2^64-1|18,446,744,073,709,551,615]]<ref name="uint64.max">
{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.uint64.maxvalue |title=.NET UInt64.MaxValue Field }}
</ref>}}
|-
|-
! rowspan="2" style="white-space: preserve nowrap; text-align:center;" | [[128-bit computing|128-bit]]
| rowspan="2" style="white-space: preserve nowrap; text-align:center;" | int128,<ref name="int128">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.int128|title=.NET Int128 Struct }}</ref> uint128<ref name="uint128">{{cite web |url=https://learn.microsoft.com/en-us/dotnet/api/system.uint128 |title=.NET UInt128 Struct }}</ref>
| rowspan="2" style="white-space: preserve nowrap; text-align:center;" | 2<sup>128</sup> − 1 || {{small|−170,141,183,460,469,231,731,687,303,715,884,105,728}} || {{small|0}}
|-
|-
| {{small|170,141,183,460,469,231,731,687,303,715,884,105,727}} || {{small|340,282,366,920,938,463,463,374,607,431,768,211,455}}
|-
|}
 
{{notelist|refs=
{{efn|name=alias|The integer (int) data type typically uses [[two's complement]] thus are signed. The 'u' prefix designates the unsigned implementation.}}
{{efn|name=signed|Signed Ranges are assuming [[two's complement]]}}
{{efn|name=byte|The byte data type is typically unsigned by default. The 's' prefix designates the signed implementation.}}
{{efn|name=common2005|The most common for personal computers {{as of|2005|lc=on}}.}}
{{efn|name=common2025|The most common for personal computers {{as of|2025|lc=on}}.}}
}}
 
 
When an unsigned arithmetic operation produces a result larger than the maximum above for an N-bit integer, an overflow reduces the result to [[Modulo operation|modulo]] N-th power of 2, retaining only the least significant bits of the result and effectively causing a ''wrap around''.
Line 24 ⟶ 92:
 
{{anchor|Security ramifications}}
Such wraparoundwrap around may cause security detriments&mdash;if an overflowed value is used as the number of bytes to allocate for a buffer, the buffer will be allocated unexpectedly small, potentially leading to a [[buffer overflow]] which, depending on the use of the buffer, might in turn cause arbitrary code execution.
 
If the variable has a [[Signed number representations|signed integer]] type, a program may make the assumption that a variable always contains a positive value. An integer overflow can cause the value to wrap and become negative, which violates the program's assumption and may lead to unexpected behavior (for example, 8-bit integer addition of 127 + 1 results in −128, a two's complement of 128). (A solution for this particular problem is to use unsigned integer types for values that a program expects and assumes will never be negative.)
Line 38 ⟶ 106:
For an unsigned type, when the ideal result of an operation is outside the type's representable range and the returned result is obtained by wrapping, then this event is commonly defined as an overflow. In contrast, the C11 standard defines that this event is not an overflow and states "a computation involving unsigned operands can never overflow."<ref name="auto"/>
 
When the ideal result of an integer operation is outside the type's representable range and the returned result is obtained by clamping, then this event is commonly defined as a saturation. Use varies as to whether a saturation is or is not an overflow. To eliminate ambiguity, the terms wrapping overflow<ref>{{cite web |url=https://www.mathworks.com/help/simulink/gui/wrap-on-overflow.html?searchHighlight=overflow&s_tid=doc_srchtitle |title=Wrap on overflow - MATLAB & Simulink |website=www.mathworks.com}}</ref> and saturating overflow<ref>{{cite web |url=https://www.mathworks.com/help/simulink/gui/saturate-on-overflow.html?searchHighlight=overflow&s_tid=doc_srchtitle |title=Saturate on overflow - MATLAB & Simulink |website=www.mathworks.com}}</ref> can be used.
 
Integer Underflow is an improper term used to signify the negative side of overflow. This terminology confuses the prefix "over" in overflow to be related to the [[Sign (mathematics)|sign]] of the number. Overflowing is related the boundary of bits, specifically the number's bits overflowing. In [[two's complement]] this overflows into the sign bit. Many references can be found to integer underflow, but lack merit. For example: CWE-191 provides two code examples that are classic overflow and cast exceptions. CWE-191 then circularly references ''24 Deadly Sins of Software Security''.<ref>{{cite web |url=https://cwe.mitre.org/data/definitions/191.html |title=CWE - CWE-191: Integer Underflow (Wrap or Wraparound) (3.1) |website=cwe.mitre.org}}</ref> This book does not define or give examples to integer underflow.<ref>{{cite book |title=24 Deadly Sins of Software Security|last=Le Blanc|first=David|page=120}}</ref>
Many references can be found to integer underflow.<ref>{{cite web |url=https://cwe.mitre.org/data/definitions/191.html |title=CWE - CWE-191: Integer Underflow (Wrap or Wraparound) (3.1) |website=cwe.mitre.org}}</ref><ref>{{cite web |url=https://dzone.com/articles/overflow-and-underflow-data |title=Overflow And Underflow of Data Types in Java - DZone Java |website=dzone.com}}</ref><ref>{{cite web |url=https://medium.com/@taabishm2/integer-overflow-underflow-and-floating-point-imprecision-6ba869a99033 |title=Integer Overflow/Underflow and Floating Point Imprecision |last=Mir |first=Tabish |date=4 April 2017 |website=medium.com}}</ref><ref>{{cite web |url=https://www.mozilla.org/en-US/security/advisories/mfsa2015-147/ |title=Integer underflow and buffer overflow processing MP4 metadata in libstagefright |website=Mozilla}}</ref><ref>{{cite web |url=https://developer.apple.com/library/content/documentation/Security/Conceptual/SecureCodingGuide/Articles/BufferOverflows.html#//apple_ref/doc/uid/TP40002577-SW7 |title=Avoiding Buffer Overflows and Underflows |website=developer.apple.com}}</ref> When the term integer underflow is used, it means the ideal result was closer to negative infinity than the output type's representable value closest to negative infinity. Depending on context, the definition of overflow may include all types including underflows, or it may only include cases where the ideal result was closer to positive infinity than the output type's representable value closest to positive infinity.
Apple's developer's guide similarly uses the term in a section titled, "Avoiding Integer Overflows and Underflows" but then the section examines overflows without defining or talking about integer underflows.<ref>{{cite web |url=https://developer.apple.com/library/content/documentation/Security/Conceptual/SecureCodingGuide/Articles/BufferOverflows.html#//apple_ref/doc/uid/TP40002577-SW7 |title=Avoiding Buffer Overflows and Underflows |website=developer.apple.com}}</ref> This term can also be found in bug reports and changelogs. The term maybe used improperly by the bug reporter or inexperienced engineer. These always result in a fix that is explained by another known error type such as overflow, array boundary, or improper casting.<ref>{{cite web |url=https://www.mozilla.org/en-US/security/advisories/mfsa2015-147/ |title=Integer underflow and buffer overflow processing MP4 metadata in libstagefright |website=Mozilla}}</ref> Although underflow is not possible on integer operations, [[arithmetic underflow]] is possible on [[Floating-point arithmetic|floating-point operations]].
 
When the ideal result of an operation is not an exact integer, the meaning of overflow can be ambiguous in edge cases. Consider the case where the ideal result has a value of 127.25 and the output type's maximum representable value is 127. If overflow is defined as the ideal value being outside the representable range of the output type, then this case would be classified as an overflow. For operations that have well defined rounding behavior, overflow classification may need to be postponed until after rounding is applied. The C11 standard<ref name="auto"/> defines that conversions from floating point to integer must round toward zero. If C is used to convert the floating point value 127.25 to integer, then rounding should be applied first to give an ideal integer output of 127. Since the rounded integer is in the outputs range, the C standard would not classify this conversion as an overflow.
Line 59 ⟶ 128:
| [[C (programming language)|C]], [[C++]] || modulo power of two || undefined behavior
|-
| [[C Sharp (programming language)|C#]] || colspan="2" | modulo power of 2 in unchecked context; <code>System.OverflowException</code> is raised in checked context<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/khy08726.aspx |title=Checked and Unchecked (C# Reference) |last=BillWagner |website=msdn.microsoft.com|date=8 April 2023 }}</ref>
| [[C Sharp (programming of two (char is the only unsigned primitive type in Java) || modulo power of two
|-
| [[C SharpJava (programming language)|Java]] || modulo power of two (char is the only unsigned primitive type in Java) || modulo power of two
|-
| [[JavaScript]] || colspan="2" | all numbers are [[Double-precision floating-point format|double-precision floating-point]] except the new [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt BigInt]
Line 67 ⟶ 138:
| [[Python (programming language)|Python]] 2 || {{N/A}} || convert to <var>long</var> type (bigint)
|-
| [[Seed7]] || {{N/A}} || <samp>'''raise''' OVERFLOW_ERROR</samp><ref>[httphttps://seed7.sourceforge.net/manual/errors.htm#OVERFLOW_ERROR Seed7 manual], section 16.3.3 OVERFLOW_ERROR.</ref>
|-
| [[Scheme (programming language)|Scheme]] || {{N/A}} || convert to bigNum
Line 122 ⟶ 193:
On 30 April 2015, the U.S. [[Federal Aviation Administration]] announced it will order [[Boeing 787]] operators to reset its electrical system periodically, to avoid an integer overflow which could lead to loss of electrical power and [[ram air turbine]] deployment, and Boeing deployed a [[software update]] in the fourth quarter.<ref>{{cite news |title= F.A.A. Orders Fix for Possible Power Loss in Boeing 787 |first=Jad |last=Mouawad |work=[[New York Times]] |date= 30 April 2015 |url= https://www.nytimes.com/2015/05/01/business/faa-orders-fix-for-possible-power-loss-in-boeing-787.html?_r=0}}</ref> The [[European Aviation Safety Agency]] followed on 4 May 2015.<ref>{{cite web |url= http://ad.easa.europa.eu/ad/US-2015-09-07 |work=Airworthiness Directives |title=US-2015-09-07: Electrical Power – Deactivation |date=4 May 2015 |publisher=[[European Aviation Safety Agency]]}}</ref> The error happens after 2<sup>31</sup> hundredths of a second (about {{#expr:ceil(2^31/100/3600/24)}} days), indicating a 32-bit [[Signed number representations|signed]] [[Integer (computer science)|integer]].
 
Overflow bugs are evident in some computer games. In ''[[Super Mario Bros.]]'' for the [[NES]], the stored number of lives is a signed byte (ranging from −128 to 127) meaning the player can safely have 127 lives, but when the player reaches their 128th life, the counter rolls over to zero lives (although the number counter is glitched before this happens) and stops keeping count. As such, if the player then dies it's an immediate game over. This is caused by the game's data overflow that was an error of programming as the developers may not have thought said number of lives couldwould be reasonably earned in a full playthrough.{{citation needed|date=February 2025}}
 
In the arcade game ''[[Donkey Kong (arcade game)|Donkey Kong]]'', it is impossible to advance past level 22 due to an integer overflow in its time/bonus. The game calculates the time/bonus by taking the level number a user is on, multiplying it by 10, and adding 40. When they reach level 22, the time/bonus number is 260, which is too large for its 8-bit 256 value register, so it overflows to a value of 4 – too short to finish the level. In ''[[Donkey Kong Jr. Math]]'', when trying to calculate a number over 10,000, it shows only the first 4 digits. Overflow is the cause of the famous [[kill screen|"split-screen" level]] in ''[[Pac-Man]]''.<ref>{{cite web |url=http://home.comcast.net/~jpittman2/pacman/pacmandossier.html |title=The Pac-Man Dossier |last=Pittman |first=Jamey}}</ref> Such a bug also caused the ''Far Lands'' in ''[[Minecraft]]'' Java Edition which existed from the Infdev development period to Beta 1.7.3; it was later fixed in Beta 1.8. The same bug also existed in ''Minecraft'' Bedrock Edition but has since been fixed.<ref>{{cite web |url=https://minecraft.wiki/w/Far_Lands |title=Far Lands |website=Minecraft Wiki |access-date=24 September 2023 |language=en}}</ref>{{unreliable source|date=October 2024}}
 
In the [[Super Nintendo Entertainment System]] (SNES) game [[Lamborghini American Challenge]], the player can cause their amount of money to drop below $0 during a race by being fined over the limit of remaining money after paying the fee for a race, which glitches the integer and grants the player $65,535,000 more than it would have had after going negative.<ref>Archived at [https://ghostarchive.org/varchive/youtube/20211205/aNQdQPi0xMo Ghostarchive]{{cbignore}} and the [https://web.archive.org/web/20190726012137/https://www.youtube.com/watch?v=aNQdQPi0xMo&t=17m55s Wayback Machine]{{cbignore}}: {{cite web |url=https://www.youtube.com/watch?v=aNQdQPi0xMo&t=17m55s |title=Lamborghini American Challenge SPEEDRUN (13:24) |website=[[YouTube]]}}{{cbignore}}</ref>[[File:Error message due to an integer signedness bug in the stack setup code of MASM 1.00.gif|thumb|An integer signedness bug in the stack setup code emitted by the [[Pascal (programming language)|Pascal]] compiler prevented IBM–[[Microsoft Macro Assembler]] (MASM) version 1.00, a [[DOS]] program from 1981, and many other programs compiled with the same compiler, to run under some configurations with more than 512 KBKiB of memory.]]
 
IBM–[[Microsoft Macro Assembler]] (MASM) version 1.00, and likely all other programs built by the same [[Pascal (programming language)|Pascal]] compiler, had an integer overflow and signedness error in the stack setup code, which prevented them from running on newer [[DOS]] machines or emulators under some common configurations with more than 512 KB&nbsp;KiB of memory. The program either hangs or displays an error message and exits to DOS.<ref>{{cite web |last=Lenclud |first=Christophe |url=https://slions.net/threads/debugging-the-ibm-personal-computer-macro-assembler-masm-version-1-00.33/ |title=Debugging IBM MACRO Assembler Version 1.00|date=21 April 2017 }}</ref>
 
In August 2016, a [[casino]] machine at [[Resorts World]] casino printed a prize ticket of $42,949,672.76 as a result of an overflow bug. The casino refused to pay this amount, calling it a malfunction, using in their defense that the machine clearly stated that the maximum payout was $10,000, so any prize exceeding that had to be the result of a programming bug. The [[New York State Gaming Commission]] ruled in favor of the casino.<ref>{{cite web |last=Kravets |first=David |date=June 15, 2017 |url=https://arstechnica.com/tech-policy/2017/06/sorry-maam-you-didnt-win-43m-there-was-a-slot-machine-malfunction |title=Sorry ma'am you didn't win $43M – there was a slot machine 'malfunction' |website=Ars Technica}}</ref>
Line 134 ⟶ 205:
==See also==
*[[Carry (arithmetic)]]
*[[Buffer overflow]]
*[[Stack buffer overflow]]
*[[Heap overflow]]
*[[Modular arithmetic]]
*[[Nuclear Gandhi]]
*[[Pointer swizzling]]
*[[Software testing]]
*[[Static program analysis]]
*[[Unix signal]]
 
==References==