How to fix a corrupt Solaris package database

When trying to remove package SMCsudo you get the error

#pkgrm SMCsudo

The following package is currently installed:
SMCsudo sudo
(sparc) 1.6.8p4

Do you want to remove this package? y

## Removing installed package instance
(A previous attempt may have been unsuccessful.)
## Verifying package dependencies.
## Processing package information.
## Removing pathnames in class
/usr/local/sbin
/usr/local/man
/usr/local/libexec
/usr/local/etc
/usr/local/doc
/usr/local/bin
## Updating system information.
pkgrm: ERROR: bad read of contents file
pkgrm: ERROR: pathname=/usr/lib/iconv/sparcv9/UTF-8%PCK.so
pkgrm: ERROR: problem=no memory for package information

do

# cd /var/sadm/pkg

which is where the package database is located

then delete the offending package that you are trying to remove.

rm -rf SMCsudo

Then the package is removed the ugly (hack) way.

So then you can now install thenewer version of the same package.

# pkgadd -d /tmp/SMCsudo