{"id":"HSEC-2026-0011","aliases":["HSEC-2026-0011"],"related":["HSEC-2026-0012"],"kind":"vulnerability","state":"published","title":"Superlinear encoding of numbers with large coefficients","summary":"# Superlinear encoding of numbers with large coefficients\n\nEncoding (pretty-printing) a `Scientific` number whose coefficient has many\ndigits took time quadratic in the number of digits: the decimal digits were\nextracted by repeatedly dividing the whole coefficient by 10, once per digit.\nThe `Show` instance, `Data.Text.Lazy.Builder.Scientific` and\n`Data.ByteString.Builder.Scientific` — which `aeson` uses to encode JSON\nnumbers — all share this code path. A number with one million digits took\nabout a minute to show, and about a tenth of a second after the fix.\n\nThis is a denial-of-service risk for applications that decode numbers from an\nuntrusted source and encode them again, e.g. JSON proxies, loggers or API\ngateways built on `aeson`.\n\n## Resolution\n\n`scientific-0.3.9.0` reimplemented `normalize` and `toDecimalDigits` (the\ndigit-extraction primitive) to be practically linear in the coefficient size.\n\nNote that `scientific-0.3.9.0` introduced a regression of its own; see\nHSEC-2026-0012. Upgrade\ndirectly to `scientific-0.3.10.0` or later, which fixes both issues.\n\n## Credits\n\nReported by Andrzej Rybczak (@arybczak); fixed by Oleg Grenrus (@phadej).","summaryFormat":"markdown","summarySource":"hsec","descriptions":[{"lang":"en","text":"# Superlinear encoding of numbers with large coefficients\n\nEncoding (pretty-printing) a `Scientific` number whose coefficient has many\ndigits took time quadratic in the number of digits: the decimal digits were\nextracted by repeatedly dividing the whole coefficient by 10, once per digit.\nThe `Show` instance, `Data.Text.Lazy.Builder.Scientific` and\n`Data.ByteString.Builder.Scientific` — which `aeson` uses to encode JSON\nnumbers — all share this code path. A number with one million digits took\nabout a minute to show, and about a tenth of a second after the fix.\n\nThis is a denial-of-service risk for applications that decode numbers from an\nuntrusted source and encode them again, e.g. JSON proxies, loggers or API\ngateways built on `aeson`.\n\n## Resolution\n\n`scientific-0.3.9.0` reimplemented `normalize` and `toDecimalDigits` (the\ndigit-extraction primitive) to be practically linear in the coefficient size.\n\nNote that `scientific-0.3.9.0` introduced a regression of its own; see\nHSEC-2026-0012. Upgrade\ndirectly to `scientific-0.3.10.0` or later, which fixes both issues.\n\n## Credits\n\nReported by Andrzej Rybczak (@arybczak); fixed by Oleg Grenrus (@phadej).","format":"markdown","source":"hsec"}],"published":"2026-11-03T22:32:58.000Z","modified":"2026-11-03T22:45:02.729Z","severities":[],"cwes":[],"affected":[{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.3.9.0"}],"ecosystem":"Hackage","package":"scientific","purl":"pkg:hackage/scientific","source":"hsec"}],"references":[{"url":"https://github.com/basvandijk/scientific/pull/109","tags":["report"],"sources":["hsec"]},{"url":"https://github.com/basvandijk/scientific/pull/116","tags":["fix"],"sources":["hsec"]},{"url":"https://github.com/basvandijk/scientific/pull/117","tags":["fix"],"sources":["hsec"]},{"url":"https://www.reddit.com/r/haskell/comments/1xbj59g/dont_use_scientific_for_calculations_it_can/","tags":["discussion"],"sources":["hsec"]}],"credits":[],"sources":[{"source":"hsec","name":"Haskell Security Advisories","id":"HSEC-2026-0011","url":"https://osv.dev/vulnerability/HSEC-2026-0011","licence":"CC0-1.0","modified":"2026-11-03T22:45:02.729Z"}],"updatedAt":"2026-11-25T22:56:25.654Z"}