Fixing a 20-Year-Old Bug in Enlightenment E16
By Kamila Szewczyk

AI Summary
As someone who was born in 2004, I find it fascinating to use the 1997 window manager, Enlightenment E16, daily. Despite its age, it remains a lightweight and customizable tool for keyboard enthusiasts like me. However, while preparing lecture slides, I encountered a persistent bug that froze my desktop whenever I opened a specific PDF. This bug, dating back to 2006, was traced to a faulty implementation of Newton's algorithm in the code.
## The Bug
The issue was reproducible: opening the PDF in Atril consistently froze the desktop. Using gdb, I discovered that the problem lay in imlib2's font cache, specifically in the TextstateTextFitMB function. This function attempts to fit a string into a limited pixel width by truncating characters, but it was stuck in an infinite loop due to a logic error.
## The Problematic Function
The function employed a Newton-style search to determine how many characters to remove, but it lacked an iteration limit, causing it to oscillate endlessly between two states. The exit tolerance was too tight, and the method failed to converge, especially with longer titles.
## The Fix
To resolve this, I implemented three defensive changes: capping iteration counts at 32 to ensure termination, flooring nuke_count at 1 to prevent degenerate strings, and flooring cw at 1 to avoid divide-by-zero errors. These changes stabilized the function and ensured it could handle long titles without freezing.
## A Philosophical Detour
This experience highlights the risks of both old and new software. While newer software may introduce fresh bugs, older software maintained by skilled developers tends to become more stable over time. However, both can be vulnerable to supply chain attacks, as demonstrated by past incidents like the XZ Utils backdoor. Ultimately, using older software like E16 allows me to implement necessary features myself and maintain control over my system's security.
Key Concepts
A numerical method used to find successively better approximations to the roots (or zeroes) of a real-valued function. It is known for its fast convergence under the right conditions.
The implied cost of additional rework caused by choosing an easy solution now instead of using a better approach that would take longer. It often accumulates in older codebases.
Category
ProgrammingOriginal source
https://iczelia.net/posts/e16-20-year-old-bug/More on Discover
Summarized by Mente
Save any article, video, or tweet. AI summarizes it, finds connections, and creates your to-do list.
Start free, no credit card