Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:52:23+00:00 2026-06-11T05:52:23+00:00

I have a simple test runner for the bug which is in my OpenPGP

  • 0

I have a simple test runner for the bug which is in my OpenPGP module https://github.com/singpolyma/OpenPGP-Haskell/blob/master/Data/OpenPGP.hs:

module Main where

import Data.OpenPGP
import Data.Binary (encode, decode)

packet = EmbeddedSignaturePacket (signaturePacket 2 168 ECDSA SHA256 [] [SignatureCreationTimePacket 1013401916,IssuerPacket "36FE856F4219F1C7"] 48065 [MPI 4,MPI 11,MPI 60,MPI 69,MPI 37,MPI 33,MPI 18,MPI 72,MPI 41,MPI 36,MPI 43,MPI 41,MPI 53,MPI 9,MPI 53,MPI 35,MPI 3,MPI 40,MPI 14,MPI 79,MPI 1,MPI 4,MPI 51,MPI 23,MPI 62,MPI 62,MPI 62,MPI 7,MPI 68,MPI 51,MPI 13,MPI 49,MPI 8,MPI 64,MPI 32,MPI 50,MPI 59,MPI 17,MPI 43,MPI 12,MPI 67,MPI 5,MPI 67,MPI 5,MPI 25,MPI 63,MPI 0,MPI 53,MPI 2,MPI 36,MPI 83,MPI 39,MPI 54,MPI 65,MPI 54,MPI 35,MPI 62,MPI 63,MPI 26,MPI 4,MPI 82,MPI 57,MPI 85,MPI 71,MPI 43,MPI 77])

main = print $ decode (encode packet) == packet

If you compile this (on ghc 7.4.1) with:

ghc -O0 -fforce-recomp --make t.hs

It works as expected (that is, it prints True), but if you compile like this:

ghc -O1 -fforce-recomp --make t.hs

or this:

ghc -O2 -fforce-recomp --make t.hs

It will print False.

I’m not using any extensions (except a trivial use of CPP) or low-level or unsafe calls, and the behaviour should be from my library and not a dependency, since it’s only my code that is getting recompiled here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:52:25+00:00Added an answer on June 11, 2026 at 5:52 am

    It’s an error in your code. Consider

    MPI 63,MPI 0,MPI 53
           ^^^^^
    

    and

    instance BINARY_CLASS MPI where
        put (MPI i) = do
            put (((fromIntegral . B.length $ bytes) - 1) * 8
                    + floor (logBase (2::Double) $ fromIntegral (bytes `B.index` 0))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    + 1 :: Word16)
        putSomeByteString bytes
        where
        bytes = if B.null bytes' then B.singleton 0 else bytes'
        bytes' = B.reverse $ B.unfoldr (\x ->
                        if x == 0 then Nothing else
                               Just (fromIntegral x, x `shiftR` 8)
                 ) (assertProp (>=0) i)
    

    Now, if we encode MPI 0, bytes' is empty, thus bytes = B.singleton 0 and hence bytes `B.index` 0 is 0.

    But logBase 2 0 is -Infinity, and floor is only well-defined for finite values (within the range of the target type).

    When compiling without optimisations, floor uses the bit-pattern via decodeFloat. Then floor (logBase 2 0) yields 0 for all standard fixed-width integer types.

    With optimisations, a rewrite-rule is active and floor uses the primop double2Int#, which returns whatever the hardware does, on x86 resp. x86-64, that’s minBound :: Int, as far as I know, regardless of the bit-pattern. The relevant code is

    floorDoubleInt :: Double -> Int
    floorDoubleInt (D# x) =
        case double2Int# x of
          n | x <## int2Double# n   -> I# (n -# 1#)
            | otherwise             -> I# n
    

    and of course, -Infinity < int2Double minBound, so the value becomes minBound - 1, which usually is maxBound.

    Of course that causes a wrong result, since now the “length” that is put for MPI 0 becomes 0, and the 0 byte put after the “length” field is interpreted as part of the “length” of the next MPI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Action class which I want to unit test: package com.gam.action.test;
I have some simple test code which I am trying to generate AVX optimized
I have a Java Project in which I am writing a simple JUNIT test
I have a simple test case failing in Django: Model (app/models.py): from django.db import
I have a simple test application (C# console application) that does an HTTP GET
I have this simple test project just to test the IncludeExceptionDetailInFaults behavior. public class
I have created a simple test form with FormBorderStyle = FixedToolWindow by default and
I have a simple unit test case (extensive question here ) on a configuration
I have made a simple test application for the issue, two winforms each containing
I have a very simple test page for PHP session. <?php session_start(); if (isset($_SESSIONS['views']))

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.