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
## Updating system information.
pkgrm: ERROR: bad read of contents file
pkgrm: ERROR: pathname=/usr/lib/iconv/sparcv9/
pkgrm: ERROR: problem=no memory for package information


# 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