peass-ng/PEASS-ng · error · IOException
extra data found after object
Error message
extra data found after object
What it means
Asn1Object.FromByteArray parses exactly one ASN.1 object and then verifies the underlying MemoryStream was fully consumed. Leftover bytes after the first object mean the array holds extra trailing data, so IOException is thrown.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/Asn1Object.cs:24
public abstract class Asn1Object
: Asn1Encodable
{
/// <summary>Create a base ASN.1 object from a byte array.</summary>
/// <param name="data">The byte array to parse.</param>
/// <returns>The base ASN.1 object represented by the byte array.</returns>
/// <exception cref="IOException">
/// If there is a problem parsing the data, or parsing an object did not exhaust the available data.
/// </exception>
public static Asn1Object FromByteArray(
byte[] data)
{
try
{
MemoryStream input = new MemoryStream(data, false);
Asn1InputStream asn1 = new Asn1InputStream(input, data.Length);
Asn1Object result = asn1.ReadObject();
if (input.Position != input.Length)
throw new IOException("extra data found after object");
return result;
}
catch (InvalidCastException)
{
throw new IOException("cannot recognise object in byte array");
}
}
/// <summary>Read a base ASN.1 object from a stream.</summary>
/// <param name="inStr">The stream to parse.</param>
/// <returns>The base ASN.1 object represented by the byte array.</returns>
/// <exception cref="IOException">If there is a problem parsing the data.</exception>
public static Asn1Object FromStream(
Stream inStr)
{
try
{
return new Asn1InputStream(inStr).ReadObject();View on GitHub (pinned to 53fb989abc)
Solutions
- Trim the array to the exact length of the first ASN.1 object before calling FromByteArray
- If multiple objects are expected, read them sequentially with Asn1InputStream.ReadObject in a loop instead of FromByteArray
- Fix the offset/length used when extracting the sub-array
- Catch IOException and inspect input.Position vs Length to locate the extra data
Example fix
// before
byte[] blob = new byte[fileBytes.Length - 16]; // extra trailing bytes remain
Asn1Object o = Asn1Object.FromByteArray(blob);
// after
// parse all objects sequentially
Asn1InputStream s = new Asn1InputStream(new MemoryStream(fileBytes));
Asn1Object o;
while ((o = s.ReadObject()) != null) { Handle(o); } Defensive patterns
Strategy: validation
Validate before calling
static byte[] ExactObjectSlice(byte[] blob, int offset, int contentLen)
{
// contentLen = declared DER content length + header size
int headerSize = 2;
byte lb = blob[offset + 1];
if (lb > 0x7f) headerSize = 2 + (lb & 0x7f);
int total = headerSize + contentLen;
byte[] slice = new byte[total];
Array.Copy(blob, offset, slice, 0, total);
return slice;
} Try / catch
try { Asn1Object o = Asn1Object.FromByteArray(data); }
catch (IOException ex) when (ex.Message.Contains("extra data"))
{
// trailing bytes after first object: slice or loop-parse instead
} Prevention
- Use Asn1InputStream.ReadObject in a loop for multi-object data
- Trim arrays to the exact object length before FromByteArray
- Fix offset/length arithmetic when extracting sub-blobs
When it happens
Trigger: Passing a byte[] that contains an ASN.1 object followed by additional bytes — e.g. a DER object concatenated with padding, signatures, or a second object; a blob extracted with a too-large length.
Common situations: Concatenated certificate chains parsed as a single object; PKCS#7 blobs sliced incorrectly; arrays copied from a larger buffer with wrong length arithmetic.
Related errors
- unknown object encountered in constructed OCTET STRING:
- unknown tag {tagNo} encountered
- DER length more than 4 bytes:
- corrupted stream - negative length found
- BOOLEAN value should have 1 byte in it
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/2f00f3261ca8ebb1.
Report an issue: GitHub.