std/handsum: make 1:1 aspect ratio be landscape
diff --git a/lib/handsum/handsum.go b/lib/handsum/handsum.go
index a478ba8..f18b4d0 100644
--- a/lib/handsum/handsum.go
+++ b/lib/handsum/handsum.go
@@ -292,19 +292,22 @@
 		return ErrBadArgument
 	}
 
-	aspectRatio := byte(0x0F)
-	if srcW > srcH { // Landscape.
+	aspectRatio := byte(0)
+	if srcW >= srcH { // Landscape.
 		a := ((int64(srcH) * 32) + int64(srcW)) / (2 * int64(srcW))
 		if a <= 0 {
 			a = 1
 		}
 		aspectRatio = byte(a-1) | 0x00
-	} else if srcW < srcH { // Portrait.
+	} else { // Portrait.
 		a := ((int64(srcW) * 32) + int64(srcH)) / (2 * int64(srcH))
 		if a <= 0 {
 			a = 1
 		}
 		aspectRatio = byte(a-1) | 0x10
+		if aspectRatio == 0x1F { // Reserved for future expansion.
+			aspectRatio = 0x0F
+		}
 	}
 
 	alphasQuadBlock := lowleveljpeg.QuadBlockU8{}
@@ -465,6 +468,10 @@
 	if !ok {
 		return image.Config{}, ErrNotAHandsumFile
 	}
+	w, h, ok := decodeWidthAndHeight(buf[2])
+	if !ok {
+		return image.Config{}, ErrNotAHandsumFile
+	}
 
 	cm := color.GrayModel
 	if c == ColorRGB {
@@ -473,7 +480,6 @@
 		cm = color.NRGBAModel
 	}
 
-	w, h := decodeWidthAndHeight(buf[2])
 	return image.Config{
 		ColorModel: cm,
 		Width:      w,
@@ -509,6 +515,10 @@
 	if _, err := io.ReadFull(r, buf[fileSizeHeader:fileSize(c, q)]); err != nil {
 		return nil, err
 	}
+	dstW, dstH, ok := decodeWidthAndHeight(buf[2])
+	if !ok {
+		return nil, ErrNotAHandsumFile
+	}
 
 	bitOffset := 3 * 8
 	decodeBlock := decodeBlockFuncs[q]
@@ -548,19 +558,20 @@
 		}
 	}
 
-	dstW, dstH := decodeWidthAndHeight(buf[2])
 	return finishDecode(dstW, dstH, c, &lumaQuadBlockU8, &cbQuadBlockU8, &crQuadBlockU8, &aaQuadBlockU8), nil
 }
 
-func decodeWidthAndHeight(buf2 byte) (w int, h int) {
-	if (buf2 & 0x10) == 0 { // Landscape.
+func decodeWidthAndHeight(buf2 byte) (w int, h int, ok bool) {
+	if (buf2 & 0x1F) == 0x1F {
+		return 0, 0, false
+	} else if (buf2 & 0x10) == 0x00 { // Landscape.
 		w = 16
 		h = 1 + int(buf2&0x0F)
 	} else { // Portrait.
 		w = 1 + int(buf2&0x0F)
 		h = 16
 	}
-	return w, h
+	return w, h, true
 }
 
 type decodeBlockFunc func(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int
diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c
index 954ee55..6c4e19f 100644
--- a/release/c/wuffs-unsupported-snapshot.c
+++ b/release/c/wuffs-unsupported-snapshot.c
@@ -51002,7 +51002,10 @@
       goto exit;
     }
     self->private_impl.f_quality = ((v_c32 >> 5u) & 3u);
-    if ((v_c32 & 16u) == 0u) {
+    if ((v_c32 & 31u) == 31u) {
+      status = wuffs_base__make_status(wuffs_handsum__error__bad_header);
+      goto exit;
+    } else if ((v_c32 & 16u) == 0u) {
       self->private_impl.f_width = 16u;
       self->private_impl.f_height = ((v_c32 & 15u) + 1u);
     } else {
diff --git a/std/handsum/decode_handsum.wuffs b/std/handsum/decode_handsum.wuffs
index afa07c0..23c84a2 100644
--- a/std/handsum/decode_handsum.wuffs
+++ b/std/handsum/decode_handsum.wuffs
@@ -78,7 +78,9 @@
     }
     this.quality = (c32 >> 5) & 3
 
-    if (c32 & 0x10) == 0x00 {  // Landscape.
+    if (c32 & 0x1F) == 0x1F {  // Reserved for future expansion.
+        return "#bad header"
+    } else if (c32 & 0x10) == 0x00 {  // Landscape.
         this.width = 16
         this.height = (c32 & 0x0F) + 1
     } else {  // Portrait.