Subject: [PATCH] Catch "file truncated" errors from objdump and warn about them. A version of binutils recently (as of the time of writting) uploaded to sid, correctly, started to emit this error instead of just saying the binary was corrupted.

From: Raphael Geissert <[email-masked]>
Date: Sun, 1 Mar 2009 19:00:45 -0600

This affected the binary-from-other-arch test since it only uses the header
of an ELF object.
---
 checks/binaries                       |    2 ++
 checks/binaries.desc                  |    7 +++++++
 collection/objdump-info               |    2 ++
 lib/Lintian/Collect/Binary.pm         |    2 ++
 t/COVERAGE                            |    3 ++-
 t/tests/binaries-from-other-arch/desc |    2 +-
 t/tests/binaries-from-other-arch/tags |    2 +-
 7 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/checks/binaries b/checks/binaries
index d718dcc..1039522 100644
--- a/checks/binaries
+++ b/checks/binaries
@@ -102,6 +102,8 @@ foreach my $file (sort keys %{$info->objdump_info}) {
     foreach (@{$objdump->{NOTES}}) {
 	if (m/^File format not recognized$/) {
             tag "apparently-corrupted-elf-binary", "$file";
+	} elsif (m/^File truncated$/) {
+            tag "apparently-truncated-elf-binary", "$file";
 	} elsif (m/^Packed with UPX$/) {
 	    tag "binary-file-compressed-with-upx", "$file";
 	} elsif (m/^Invalid operation$/) {
diff --git a/checks/binaries.desc b/checks/binaries.desc
index a7d82b0..c116b85 100644
--- a/checks/binaries.desc
+++ b/checks/binaries.desc
@@ -157,6 +157,13 @@ Info: This appears to be an ELF file but objdump -T doesn't recognize it
  non-native binaries are handled correctly, or it may be a
  misidentification of a file as ELF that actually isn't.
 
+Tag: apparently-truncated-elf-binary
+Severity: normal
+Certainty: possible
+Info: This appears to be an ELF file but objdump believes it is truncated.
+ This may be a mistake or a corrupted file, or it may be a
+ misidentification of a file as ELF that actually isn't.
+
 Tag: missing-dependency-on-libc
 Severity: serious
 Certainty: certain
diff --git a/collection/objdump-info b/collection/objdump-info
index 18ed175..803ca6f 100755
--- a/collection/objdump-info
+++ b/collection/objdump-info
@@ -85,6 +85,8 @@ while (<FILES>) {
 			$failed = 0;
 		    } elsif (m/File format not recognized$/) {
 			$failed = 0;
+		    } elsif (m/File truncated$/) {
+			$failed = 0;
 		    }
 		}
 		close PIPE;
diff --git a/lib/Lintian/Collect/Binary.pm b/lib/Lintian/Collect/Binary.pm
index 3eb82fb..7145545 100644
--- a/lib/Lintian/Collect/Binary.pm
+++ b/lib/Lintian/Collect/Binary.pm
@@ -219,6 +219,8 @@ sub objdump_info {
                 $dynsyms = 1;
             } elsif (m/^objdump: (.*?): File format not recognized$/) {
                 push @{$file->{NOTES}}, "File format not recognized";
+            } elsif (m/^objdump: (.*?): File truncated$/) {
+                push @{$file->{NOTES}}, "File truncated";
             } elsif (m/^objdump: \.(.*?): Packed with UPX$/) {
                 push @{$file->{NOTES}}, "Packed with UPX";
             } elsif (m/objdump: \.(.*?): Invalid operation$/) {
diff --git a/t/COVERAGE b/t/COVERAGE
index ba27255..f36517f 100644
--- a/t/COVERAGE
+++ b/t/COVERAGE
@@ -1,7 +1,8 @@
-Last generated 2009-02-22
+Last generated 2009-03-02
 
 The following tags are not tested by the test suite:
 
+binaries apparently-corrupted-elf-binary
 binaries arch-dependent-file-in-usr-share
 binaries binary-compiled-with-profiling-enabled
 binaries binary-file-compressed-with-upx
diff --git a/t/tests/binaries-from-other-arch/desc b/t/tests/binaries-from-other-arch/desc
index 673a06a..0d0e818 100644
--- a/t/tests/binaries-from-other-arch/desc
+++ b/t/tests/binaries-from-other-arch/desc
@@ -4,5 +4,5 @@ Architecture: any
 Version: 1.0
 Description: Test package with a pseudo binary from a different architecture
 Test-For:
- apparently-corrupted-elf-binary
+ apparently-truncated-elf-binary
  binary-from-other-architecture
diff --git a/t/tests/binaries-from-other-arch/tags b/t/tests/binaries-from-other-arch/tags
index 2821a19..e6749bd 100644
--- a/t/tests/binaries-from-other-arch/tags
+++ b/t/tests/binaries-from-other-arch/tags
@@ -1,4 +1,4 @@
 E: binaries-from-other-arch: binary-from-other-architecture ./usr/bin/elfobject
 E: binaries-from-other-arch: statically-linked-binary ./usr/bin/elfobject
-W: binaries-from-other-arch: apparently-corrupted-elf-binary ./usr/bin/elfobject
+W: binaries-from-other-arch: apparently-truncated-elf-binary ./usr/bin/elfobject
 W: binaries-from-other-arch: binary-without-manpage usr/bin/elfobject