Sunday, February 04, 2018

Fixing Windows Update problems

I've been experiencing some Windows Update problems, in particular Windows update endlessly "Checking for updates". After much trial and error I found a How-To Geek article by Walter Glenn helpful. In particular, installing and using the WSUS Offline Update was necessary before cleaning out the wuauserv cache.

Thursday, February 01, 2018

Reading large JP2 files on Fedora

I recently had to analyze some very large (>100 megapixel) JP2 files and ran into the following problem on my Fedora 27 machine:

 jiv sat16_abi_fd6_l1b_CTfullimage_BA03_2018-030-204905.jp2  
 maximum number of samples exceeded (117679104 > 67108864)  
 error: cannot decode code stream  
 error: cannot load image data  
 cannot load image  
 Segmentation fault (core dumped)  

I got the same error "maximum number of samples exceeded" message from octave's imread or using gimp, which lead me to this link pointing to a compiled in limit in libjasper.

The solution is to compile a custom version of libjasper with a larger limit. This is straightforward, but how to get it done cleanly in terms of RPMs?

1:  sudo dnf -y install rpm-build rpmdevtools  
2:  rpmdev-setuptree  
3:  rpm -ivh jasper-2.0.14-1.fc27.src.rpm  
4:  cd rpmbuild/BUILD  
5:  tar xzvf ../SOURCES/jasper-2.0.14.tar.gz  
6:  cp -R jasper-2.0.14 jasper-2.0.14p  
7:  geany ./jasper-2.0.14p/jasper-2.0.14/builder/src/libjasper/include/jasper/jas_config.h  
8:  diff -puNr jasper-2.0.14/ jasper-2.0.14p/ > ../SOURCES/jasper-2.0.14-largefile.patch  
9:  cd ../SPECS  
10:  geany jasper.spec  
11:  QA_RPATHS=$(( 0x0001|0x0010 )) rpmbuild -ba jasper.spec  
12:  ls ../RPMS/x86_64/  

For step #7 we're making a single line change to move from a 64 megapixel limit to something closer to what we want, in my case 512 megapixels. Here is the diff generated in step #8:

1:  diff -puNr jasper-2.0.14/src/libjasper/include/jasper/jas_config.h.in jasper-2.0.14p/src/libjasper/include/jasper/jas_config.h.in  
2:  --- jasper-2.0.14/src/libjasper/include/jasper/jas_config.h.in    2017-09-14 19:20:10.000000000 -0400  
3:  +++ jasper-2.0.14p/src/libjasper/include/jasper/jas_config.h.in    2018-02-01 11:27:13.784393051 -0500  
4:  @@ -61,7 +61,7 @@  
5:   #endif  
6:   #if !defined(JAS_DEC_DEFAULT_MAX_SAMPLES)  
7:  -#define JAS_DEC_DEFAULT_MAX_SAMPLES (64 * ((size_t) 1048576))  
8:  +#define JAS_DEC_DEFAULT_MAX_SAMPLES (512 * ((size_t) 1048576))  
9:   #endif  
10:   #if defined(__GNUC__) && !defined(__clang__)  

A number of changes need to be made to the spec file in step #10. I changed the release to something that lets me know I made this, switched off debug builds (as they seem to cause trouble), and added the patch.Only the added lines are shown below.

 Release: 2dks%{?dist}  
 ...  
 %global debug_package %{nil}  
 ...  
 Patch102: jasper-2.0.14-largefile.patch  
 ...  
 %if "%{_arch}" == "x86_64"  
 %patch102 -p1 -b .largefile  
 %endif  
 
Once the RPMs are built (step #11) as user you can install them as root.

1:  su - # enter password  
2:  cd ~<username>/rpmbuild/RPMS/x86_64/  
3:  dnf install `ls | grep -v debug | xargs`  
4:  # if you need to go back to the old system versions use  
5:  # dnf downgrade jasper jasper-devel jasper-libs jasper-utils  

Then check that you can load your large JP2 file without that error message. If not, its likely you made a mistake in modifying the .h file, creating the patch or the spec file. (I had to try this a few times before I got it right.)

You can lock down these rpms so that dnf upgrades wont replace your hard work using dnf versionlock, see e.g., here.

Some useful links on dealing with source rpms on Fedora/Redhat systems: