Page MenuHome GnuPG

gpg: [don't know]: invalid packet (ctb=2d)
Closed, ResolvedPublic

Description

I have an issue like bug 997. The whole file gets decrypted, but it finishes
with this:

gpg: [don't know]: invalid packet (ctb=2d)
gpg: [don't know]: invalid packet (ctb=2d)

It's happening with an automated process, and about 1 out of 5 of the files it
encrypts get this issue. The files are encrypted with the -a option.

The commonality is that they are exactly 512 lines of encoded data + the
checksum line, or 32K on the nose. Like this:

...
BH0rOw1S24VKlqKfFrMujgPTp7DZOJzm6JEA2Khx3vm2L9iYL6VgltJZS7sAeuc1

yz2X

-----END PGP MESSAGE-----

If you want, I can send you a few sample of the source file + encrypted files.

I can't seem to replicate the encryption on a different machine, don't know why.

The encrypting software is 1.4.9. I tried decrypting with both 1.4.9 and 1.4.10.

Details

Version
1.4.10

Event Timeline

mlongtin set Version to 1.4.10.
mlongtin added a subscriber: mlongtin.

To tarck this down I would also need the key. Can you create such a broken
message using one of the example keys (e.g. alfa@example.net)? IF so, feel free
to send it to me directly wk@gnupg.org - if the data is kind of sensitive, feeel
free to encrypt. Due to anti-spam meastures it is best to send a gzipped
tarball or any other gzipped data; or send me an URL.

I tracked it down with GPG (hadn't used that in 10 years).

Basically, if the CRC is alone on a line by itself, the function radix64_read in
armor.c returns -1 because of this line:

if( !n && !onlypad )
    rc = -1;

This cause iobuf.c:underflow to deallocate the filter, leaving the file_filter
alone. So next time it reads using the file_filter and gets the '-----END PGP
MESSAGE-----'.

If the CRC is not a line by itself, the armor_filter is not deallocated, but
reads to the end of the file first, which deallocates the file_filter, then says
it doesn't have any more data (rc=-1,len=0).

I am inclined to fix this by putting this check towards the end of radix64_read:

Line 929-941 of armor.c:
#endif

}
if(n==0)
  onlypad=1;
    }
}

if( !n && !onlypad )
    rc = -1;

*retn = n;
return rc;

}

This fixes my issue.

Included is an example of a message that once encrypted causes problems. The
message was encrypted with a public key but not signed.

Thanks for the excellent description.

werner changed Due Date from Jan 31 2009, 1:00 AM to May 31 2009, 2:00 AM.May 12 2010, 12:04 PM
werner claimed this task.
werner removed Due Date.

It turned out to be some work to reproduce the case. The length of the output
depends on the key and other factors. I created a test case which is now used
in armor.test which clearly shows this.

The bug fix was to extend David's, 4 year old fix for a key import problem.
We will release 1.4.11 in a couple of weeks.