Year 2038 problem (2038年問題)

From Wikipedia, the free encyclopedia
 
 
 
Animation showing how the date would reset, represented as a signed 32-bit integer (at 03:14:08 UTC on 19 January 2038).

The Year 2038 problem is an issue for computing and data storage situations in which time values are stored or calculated as a signed 32-bit integer, and this number is interpreted as the number of seconds since 00:00:00 UTC on 1 January 1970 (the epoch).[1] Such implementations cannot encode times after 03:14:07 UTC on 19 January 2038, a problem similar to but not entirely analogous to the Y2K problem (also known as the Millennium Bug), in which 2-digit values representing the number of years since 1900 could not encode the year 2000 or later. Most 32-bit Unix-like systems store and manipulate time in this Unix time format, so the year 2038 problem is sometimes referred to as the Unix Millennium Bug by association.php

 

 

Technical cause[edit]

The latest time that can be represented in Unix's signed 32-bit integer time format is 03:14:07 UTC on Tuesday, 19 January 2038 (231-1 = 2,147,483,647 seconds after 1 January 1970).[2] Times beyond that will wrap around and be stored internally as a negative number, which these systems will interpret as having occurred on 13 December 1901 rather than 19 January 2038. This is caused by integer overflow. The counter runs out of usable digit bits, flips the sign bit instead, and reports a maximally negative number (continuing to count up, toward zero). Resulting erroneous calculations on such systems are likely to cause problems for users and other relying parties.html

Programs that work with future dates will begin to run into problems sooner; for example a program that works with dates 20 years in the future will have to be fixed no later than 2018.java

Early problems[edit]

In May 2006, reports surfaced of an early manifestation of the Y2038 problem in the AOLserver software. The software was designed with a kludge to handle a database request that should "never" time out. Rather than specifically handling this special case, the initial design simply specified an arbitrary time-out date in the future. The default configuration for the server specified that the request should time out after one billion seconds. One billion seconds (approximately 32 years) after 01:27:28 UTC on 13 May 2006 (12 May 2006 in North America) is beyond the 2038 cutoff date. Thus, after this time, the time-out calculation overflowed and returned a date that was actually in the past, causing the software to crash. When the problem was discovered, AOLServer operators had to edit the configuration file and set the time-out to a lower value.[3][4]node

Players of games or apps which are programmed to impose waiting periods[5] are running into this problem when they attempt to work around the waiting period on devices which harbor the coding, by manually setting their devices (such as the Nexus 7[6]) to a date past 19 January 2038, but are unable to do so, since a 32-bit Unix time format is being used.mysql

Vulnerable systems[edit]

Embedded systems that use dates for either computation or diagnostic logging are most likely to be affected by the 2038 bug.linux

Many transportation systems from flight to automobiles use embedded systems extensively. In automotive systems, this may include anti-lock braking system (ABS), electronic stability control (ESC/ESP), traction control (TCS) and automatic four-wheel drive; aircraft may use inertial guidance systems and GPS receivers. However, this does not imply that all these systems will suffer from the bug. Many such systems will not require access to dates. For those that do, those systems which only track the difference between times/dates and not absolute times/dates will, by the nature of the calculation, not experience a problem. This is the case for automotive diagnostics based on legislative standards such as CARB (California Air Resources Board).[7]android

Another major use of embedded systems is in communications devices, including cell phones and Internet appliances (routers, wireless access points, etc.) which rely on storing an accurate time and date and are increasingly based on UNIX-like operating systems. For example, the bug makes some Android devices crash and not restart when the time is changed to that date.[8]git

Despite the modern 18–24 month generational update in computer systems technology, embedded systems are designed to last the lifetime of the machine in which they are a component. It is conceivable that some of these systems may still be in use in 2038. It may be impractical or, in some cases, impossible to upgrade the software running these systems, ultimately requiring replacement if 32-bit time_t limitations are to be corrected.github

MySQL database's built-in functions like UNIX_TIMESTAMP() will return 0 after 03:14:07 UTC on 19 January 2038,[9] though a bug-fix was contributed on 22 March 2017.[10]web

Data structures with time problems[edit]

Many data structures in use today have 32-bit time representations embedded into their structure. A full list of these data structures is virtually impossible to derive but there are well-known data structures that have the Unix time problem:

  • file systems (many file systems use only 32 bits to represent times in inodes)
  • binary file formats (that use 32-bit time fields)
  • databases (that have 32-bit time fields)
  • database query languages, like SQL that have UNIX_TIMESTAMP() like commands

Examples of systems utilizing data structures that may contain 32-bit time representations include:

  • embedded factory, refinery control and monitoring subsystems
  • assorted medical devices
  • assorted military devices

Any system making use of data structures containing 32-bit time representations will present risk. The degree of risk is dependent on the mode of failure.

NTP timestamps[edit]

The Network Time Protocol has a related overflow issue, which manifests itself in 2036, rather than 2038. The 64-bit timestamps used by NTP consist of a 32-bit part for seconds and a 32-bit part for fractional second, giving NTP a time scale that rolls over every 232seconds (136 years) and a theoretical resolution of 2−32 seconds (233 picoseconds). NTP uses an epoch of 1 January 1900. The first rollover occurs in 2036, prior to the UNIX year 2038 problem.

Implementations should disambiguate NTP time using a knowledge of the approximate time from other sources. Since NTP only works with the differences between timestamps and never their absolute values, the wraparound is invisible in the calculations as long as the timestamps are within 68 years of each other. However, after a wraparound the clients can still face 2 problems: 1) They receive the date 01-01-1900 00:00:00UTC, not 07 feb 2036 06:28:15 (plus minus some leap seconds) as the new time; and 2) when a client tries to adopt this time and store it in UNIX time format, as many embedded systems do, it will fail because UNIX time starts at 13 December 1901 (signed 32 bit integer) or 01 January 1970 (unsigned 32 bit integer).

This means that for NTP the rollover will be invisible for most running systems, since they will have the correct time to within a very small tolerance. However, systems that are starting up need to know the date within no more than 68 years. Given the large allowed error, it is not expected that this is too onerous a requirement. One suggested method is to set the clock to no earlier than the system build date or the release date of the current version of the NTP software. Many systems use a battery-powered hardware clock to avoid this problem.

Even so, future versions of NTP may extend the time representation to 128 bits: 64 bits for the second and 64 bits for the fractional-second. The current NTP4 format has support for Era Number and Era Offset, that when used properly should aid fixing date rollover issues. According to Mills, "The 64 bit value for the fraction is enough to resolve the amount of time it takes a photon to pass an electron at the speed of light. The 64 bit second value is enough to provide unambiguous time representation until the universe goes dim."[11][note 1]

Solutions[edit]

There is no universal solution for the Year 2038 problem. Any change to the definition of the time_t data type would result in code compatibility problems in any application in which date and time representations are dependent on the nature of the signed 32-bit time_tinteger. For example, changing time_t to an unsigned 32-bit integer, which would extend the range to the year 2106, would adversely affect programs that store, retrieve, or manipulate dates prior to 1970, as such dates are represented by negative numbers. Increasing the size of the time_t type to 64-bit in an existing system would cause incompatible changes to the layout of structures and the binary interface of functions.

There is also no universal solution for the issue with DVB and ATSC real time transmitted dates due to issues with legacy receivers. The issue has yet to be acknowledged or resolved by either organization. The only workaround would be to discontinue all time-related metadata services such as programming guides and automatic date synchronization after the affected dates. One possible option would be to create new table types for the affected part of the specifications and use ISO 8601 date strings rather than fixed integers—as are used in ISO 9660 and ISO 13346 filesystems.

Most operating systems designed to run on 64-bit hardware already use signed 64-bit time_t integers. Using a signed 64-bit value introduces a new wraparound date that is over twenty times greater than the estimated age of the universe: approximately 292 billion years from now, at 15:30:08 UTC on Sunday, 4 December 292,277,026,596. The ability to make computations on dates is limited by the fact that tm_year uses a signed 32 bit integer value starting at 1900 for the year. This limits the year to a maximum of 2,147,485,547 (2,147,483,647 + 1900).[12]

Starting with NetBSD version 6.0 (released in October 2012), the NetBSD operating system uses a 64-bit time_t for both 32-bit and 64-bit architectures. Applications that were compiled for an older NetBSD release with 32-bit time_t are supported via a binary compatibility layer, but such older applications will still suffer from the Year 2038 problem.[13]

OpenBSD since version 5.5, released in May 2014, also uses a 64-bit time_t for both 32-bit and 64-bit architectures. In contrast to NetBSD, there is no binary compatibility layer. Therefore, applications expecting a 32-bit time_t and applications using anything different from time_t to store time values may break.[14]

Linux uses a 64-bit time_t for 64-bit architectures only; the pure 32-bit ABI is not changed due to backward compatibility.[15] There is ongoing work, mostly for embedded Linux systems, to support 64-bit time_t on 32-bit architectures, too.[16][17]

The x32 ABI for Linux (which defines an environment for programs with 32-bit addresses but running the processor in 64-bit mode) uses a 64-bit time_t. Since it was a new environment, there was no need for special compatibility precautions.[15]

Network File System version 4 has defined its time fields as struct nfstime4 {int64_t seconds; uint32_t nseconds;} since December, 2000.[18] Values greater than zero for the seconds field denote dates after the 0-hour, January 1, 1970. Values less than zero for the seconds field denote dates before the 0-hour, January 1, 1970. In both cases, the nseconds (nanoseconds) field is to be added to the seconds field for the final time representation.

Alternative proposals have been made (some of which are in use), such as storing either milliseconds or microseconds since an epoch (typically either 1 January 1970 or 1 January 2000) in a signed 64-bit integer, providing a minimum range of 300,000 years at microsecond resolution.[19][20] Other proposals for new time representations provide different precisions, ranges, and sizes (almost always wider than 32 bits), as well as solving other related problems, such as the handling of leap seconds. In particular, TAI64[21] is an implementation of the Temps Atomique International standard, the current international real-time standard for defining a second and frame of reference.

See also[edit]

Notes[edit]

  1. Jump up^ 2−64 seconds is about 54 zeptoseconds or 54 x 10−21 seconds (light would travel 16.26 picometres, or approximately 0.31 × Bohr radius), and 264 seconds is about 585 billion years.

References[edit]

  1. Jump up^ "The Open Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 Edition (definition of epoch)"IEEE and The Open GroupThe Open Group. 2004. Retrieved 7 March 2008.
  2. Jump up^ Diomidis Spinellis (2006). Code quality: the open source perspective. Effective software development series in Safari Books Online (illustrated ed.). Adobe Press. p. 49. ISBN 0-321-16607-8.
  3. Jump up^ "The Future Lies Ahead". 28 June 2006. Retrieved 19 November 2006.
  4. Jump up^ Weird "memory leak" problem in AOLserver 3.4.2/3.x 12 May 2006
  5. Jump up^ "It isn't cheating it's time travel".
  6. Jump up^ "25 Years From Today A Time For Bugs". Archived from the original on 21 January 2013. Update: I have confirmed Mikko's Android report on a Google Nexus 7 tablet running Android 4.1 Jelly Bean — Even though years beyond 2038 are listed in the Set Date and Time function of the Settings app, try to set it to a date past 1/19/2038 and it refuses.
  7. Jump up^ board, california air resources. "ARB Test Methods / Procedures"www.arb.ca.gov.
  8. Jump up^ "Sign in - Google Accounts"code.google.com.
  9. Jump up^ "aj_blk: Year 2038 Bug". Ajoeblk.blogspot.in. Retrieved 2013-03-12.
  10. Jump up^ "MySQL Bugs: #12654: 64-bit unix timestamp is not supported in MySQL functions"bugs.mysql.com.
  11. Jump up^ University of Delaware Digital Systems Seminar presentation by David Mills, 2006-04-26
  12. Jump up^ "The End of Time". 17 April 2010. Retrieved 19 March 2012.
  13. Jump up^ "Announcing NetBSD 6.0". 17 October 2012. Retrieved 18 January 2016.
  14. Jump up^ "OpenBSD 5.5 released (May 1, 2014)". 1 May 2014. Retrieved 18 January 2016.
  15. Jump up to:a b Jonathan Corbet (14 August 2013). "Pondering 2038"Archived from the original on 4 March 2016. Retrieved 9 March2016.
  16. Jump up^ Arnd Bergmann (25 March 2015). "The end of time (32bit edition)" (PDF). Archived from the original (PDF) on 22 September 2015. Retrieved 9 March 2016.
  17. Jump up^ Jonathan Corbet (5 May 2015). "System call conversion for year 2038"Archived from the original on 11 October 2015. Retrieved 9 March 2016.
  18. Jump up^ "RFC 7530".
  19. Jump up^ "Unununium Time". Archived from the original on 8 April 2006. Retrieved 19 November 2006.
  20. Jump up^ Sun Microsystems. "Java API documentation for System.currentTimeMillis()". Retrieved 29 Sep 2017.
  21. Jump up^ "TAI64".

External links[edit]

 

========================

 

2038年問題

  編輯
2038年問題是指在使用POSIX時間的32位計算機應用程序上, 格林尼治時間2038年1月19日凌晨03:14:07(北京時間:2038年1月19日中午11:14:07)以後沒法正常工做。
網絡時代,機會與危機共存,這也許是你我必須面對和必須付出的代價。「 千年蟲」解決以後,會不會有新的「蟲」出現?回答是確定的,「2038年」就是一個新的關卡。
 
中文名
2038年問題
外文名
Year 2038 problem
概    念
計算機bug(程序錯誤)
載    體
使用POSIX時間的32位應用程序
爆發時間
2038年1月19日03:14:07(UTC)

32位時間表示

編輯

前言

2038年問題演示 2038年問題演示
在計算機應用上,2038年問題可能會致使某些軟件在2038年沒法正常工做。全部使用POSIX時間表示時間的程序都將受其影響,由於它們的時間起點是 格林尼治時間1970年1月1日0時0分0秒(這個時間名叫 the Unix Epoch),它們用the Unix Epoch通過的秒數(忽略閏秒)來表示時間。這種時間表示法在類Unix(Unix-like)操做系統上是一個標準,並會影響以其C編程語言開發給其餘大部份操做系統使用的軟件。在大部分的32位操做系統上,此「time_t」數據模式使用一個有符號32位整數(signed int32)存儲計算的秒數。依照此「time_t」標準,在此格式能被表示的最後時間是第2147483647秒(表明格林尼治時間2038年1月19日凌晨03:14:07)。下一秒,即格林尼治時間2038年1月19日凌晨03:14:08,因爲32位整型 溢出,時間將會被「繞回」(wrap around)成一個負數,變成了第 -2147483648 秒(表明格林尼治時間1901年12月13日20:45:52),形成應用程序發生嚴重的時間錯誤,而沒法運行。

正文

也許你們都已經知道計算機的2000年問題是什麼概念,可是何時又冒出來一個2038年問題的呢?
用C語言編制的程序不會碰到2000年問題,可是會有2038年問題。這是由於,大多數C語言程序都使用到一個叫作「標準時間庫」的 程序庫,這個時間庫用一個標準的4字節也就是32位的形式來儲存時間信息。
當初設計的時候,這個4字節的時間格式把1970年1月1日凌晨0時0分0秒(這個時間名叫 the Unix Epoch)做爲時間起點,這時的時間值爲0。之後全部的時間都是從這個時間開始一秒一秒累積得來的。
比方說若是時間已經累積到了919642718這個數值,就是說這時距離 the Unix Epoch已通過去了919642718秒,換算一下就應該是1999年2月21日16時18分38秒。
這樣計算時間的好處在於,把任意兩個時間值相減以後,就能夠很迅速地獲得這兩個時間之間相差的秒數,而後你能夠利用別的程序把它換算成明白易懂的年月日時分秒的形式。
要是你曾經讀過一點兒關於計算機方面的書,你就會知道一個4 字節也就是32位的存儲空間的最大值是2147483647,請注意!2038年問題的關鍵也就在這裏———當時間一秒一秒地跳完2147483647那驚心動魄的最後一秒後,你猜怎麼樣?
答案是,它就會轉爲負數也就是說時間無效。那一刻的準確的時間爲2038年1月19日星期二凌晨03:14:07,以後全部用到這種「標準時間庫」的C語言程序都會碰到時間計算上的麻煩。
這就是2038年問題。
可是你們也不用太過緊張。2038年問題比 千年蟲(the Millennium bug)問題解決起來相對要容易一些,只要給那些程序換一個新版本的「標準時間庫」就能夠了,好比說,改用8字節64位的形式來存儲時間。這樣作並不怎麼費事,由於在C程序中「標準時間庫」是相對獨立的一個部分,裏面的時間表達都有本身的一套時間類型和參數(而在碰到Y2K的那些大型主機中,時間格式大都沒有一)。
說到這裏,一些冰雪聰明的菜鳥DDMM們應該能夠聯想到,WindowsNT用的是64位操做平臺,它的開始時間是1601年1月1日———可是它每過1個納秒就跳一下,所以,WindowsNT它會碰到的是2184年問題……
而在一些用64位來表示時間的平臺上,例如DigitalAlpha、SGI、Sparc等等,想要看到它們的時間出錯你得等到天荒地老———那大概是2920億年。到那時,位於獵戶座旋臂的太陽,已是黑矮星或暗黑物質,獵戶座旋臂已經被重力波震斷,銀河系大概則已經變成小型似星體了。
因此,給那些準備攢機的菜鳥DD一個建議,除非您想要把資料流傳給下一個宇宙,一臺64位的電腦已經足夠。
總之,32位的最後時間是2038年1月19日03:14:07,星期二。
64位的最後時間約2900億年後的292,277,026,596年12月4日15:30:08,星期日。

64位時間表示

編輯
新的64位 運算器能夠記錄至約2900億年後的292,277,026,596年12月4日15:30:08,星期日(UTC)。

解決進展

編輯
目前並無針對現有的CPU/操做系統搭配的簡單解決方案。直接將POSIX時間更改成64位模式將會破壞對於軟件、數據存儲以及全部與 二進制表示時間相關的部份的二進位兼容性。更改爲無符號的32位 運算器(integer)則會影響許多與時間改變相關的程序。
大部份64位操做系統已經把time_t改成64位整型。不過,其餘現有架構的改動仍在進行中,不過預期「應該能夠在2038年前完成」。然而,直到2006年,仍然有數以億計的32位操做系統在運行中,特別是許多 嵌入式系統。相對於通常電腦科技18至24個月的革命性更新,嵌入式系統可能直至使用壽命終結都不會改變。32位time_t的使用亦被編碼於文件格式,例如衆所周知的ZIP 壓縮格式。其能存在的時間遠比受影響的機器長
相關文章
相關標籤/搜索