diff mbox series

[v2,11/29] edid-decode: make all OUI handlers the same

Message ID 20210926083330.5206-12-joevt@shaw.ca (mailing list archive)
State New, archived
Headers show
Series edid-decode: bug fixes, additions, changes | expand

Commit Message

joevt Sept. 26, 2021, 8:33 a.m. UTC
Because they are the same but with different block names.

For Vendor-Specific Data Block there are a couple fixes:
1) If the length is not enough to contain an OUI, then a fail is output. I have a corrupted EDID that would cause 20000+ lines of hex to be output without this check.
2) The return statement for VSDB with unknown OUI is changed to a break statement. The code after the switch statement will be executed which causes the block to be considered as a first block or as not a hdmi vsdb.

Signed-off-by: Joe van Tunen <joevt@shaw.ca>
---
 parse-cta-block.cpp | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/parse-cta-block.cpp b/parse-cta-block.cpp
index 7568780..b4645b4 100644
--- a/parse-cta-block.cpp
+++ b/parse-cta-block.cpp
@@ -2030,6 +2030,7 @@  static void cta_hdmi_audio_block(const unsigned char *x, unsigned length)
 void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned length,
 			       bool duplicate)
 {
+	const char *block_name;
 	const char *name;
 	unsigned oui;
 	bool reverse = false;
@@ -2103,8 +2104,9 @@  void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 	switch (tag) {
 	case 0x700: cta_vcdb(x, length); break;
 	case 0x701:
+		block_name = "Vendor-Specific Video Data Block";
 		if (length < 3) {
-			data_block = std::string("Vendor-Specific Video Data Block");
+			data_block = std::string(block_name);
 			fail("Invalid length %u < 3.\n", length);
 			break;
 		}
@@ -2117,15 +2119,13 @@  void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 				reverse = true;
 		}
 		if (!name) {
-			printf("  Vendor-Specific Video Data Block, OUI %s:\n",
-			       ouitohex(oui).c_str());
+			printf("  %s, OUI %s:\n", block_name, ouitohex(oui).c_str());
 			hex_block("    ", x, length);
 			data_block.clear();
-			warn("Unknown Extended Vendor-Specific Video Data Block, OUI %s.\n",
-			     ouitohex(oui).c_str());
+			warn("Unknown %s, OUI %s.\n", block_name, ouitohex(oui).c_str());
 			break;
 		}
-		data_block = std::string("Vendor-Specific Video Data Block (") + name + ")";
+		data_block = std::string(block_name) + " (" + name + ")";
 		if (reverse)
 			fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order\n").c_str());
 		printf("  %s, OUI %s:\n", data_block.c_str(), ouitohex(oui).c_str());
@@ -2144,8 +2144,9 @@  void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 	case 0x70e: cta_svd(x, length, true); break;
 	case 0x70f: cta_y420cmdb(x, length); break;
 	case 0x711:
+		block_name = "Vendor-Specific Audio Data Block";
 		if (length < 3) {
-			data_block = std::string("Vendor-Specific Audio Data Block");
+			data_block = std::string(block_name);
 			fail("Invalid length %u < 3.\n", length);
 			break;
 		}
@@ -2158,15 +2159,13 @@  void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 				reverse = true;
 		}
 		if (!name) {
-			printf("  Vendor-Specific Audio Data Block, OUI %s:\n",
-			       ouitohex(oui).c_str());
+			printf("  %s, OUI %s:\n", block_name, ouitohex(oui).c_str());
 			hex_block("    ", x, length);
 			data_block.clear();
-			warn("Unknown Extended Vendor-Specific Audio Data Block, OUI %s.\n",
-			     ouitohex(oui).c_str());
+			warn("Unknown %s, OUI %s.\n", block_name, ouitohex(oui).c_str());
 			break;
 		}
-		data_block = std::string("Vendor-Specific Audio Data Block (") + name + ")";
+		data_block = std::string(block_name) + " (" + name + ")";
 		if (reverse)
 			fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order\n").c_str());
 		printf("  %s, OUI %s:\n", data_block.c_str(), ouitohex(oui).c_str());
@@ -2222,6 +2221,7 @@  void edid_state::cta_block(const unsigned char *x, bool duplicate)
 		x++;
 	}
 
+	const char *block_name;
 	const char *name;
 	unsigned oui;
 	bool reverse = false;
@@ -2240,6 +2240,12 @@  void edid_state::cta_block(const unsigned char *x, bool duplicate)
 		cta_svd(x, length, false);
 		break;
 	case 0x03:
+		block_name = "Vendor-Specific Data Block";
+		if (length < 3) {
+			data_block = std::string(block_name);
+			fail("Invalid length %u < 3.\n", length);
+			break;
+		}
 		oui = (x[2] << 16) + (x[1] << 8) + x[0];
 		x += 3; length -=3;
 		name = oui_name(oui);
@@ -2249,14 +2255,13 @@  void edid_state::cta_block(const unsigned char *x, bool duplicate)
 				reverse = true;
 		}
 		if (!name) {
-			printf("  Vendor-Specific Data Block, OUI %s:\n", ouitohex(oui).c_str());
+			printf("  %s, OUI %s:\n", block_name, ouitohex(oui).c_str());
 			hex_block("    ", x, length);
 			data_block.clear();
-			warn("Unknown Vendor-Specific Data Block, OUI %s.\n",
-			     ouitohex(oui).c_str());
-			return;
+			warn("Unknown %s, OUI %s.\n", block_name, ouitohex(oui).c_str());
+			break;
 		}
-		data_block = std::string("Vendor-Specific Data Block (") + name + ")";
+		data_block = std::string(block_name) + " (" + name + ")";
 		if (reverse)
 			fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order\n").c_str());
 		printf("  %s, OUI %s:\n", data_block.c_str(), ouitohex(oui).c_str());