SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Github Development
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Github Development Discussion related to SageTV Open Source Development. Use this forum for development topics about the Open Source versions of SageTV, hosted on Github.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-22-2017, 09:22 AM
kenfox kenfox is offline
Sage User
 
Join Date: Oct 2016
Location: Germany
Posts: 69
Failed to parse EPG start date

Hi there,

currently, I'm finding lots of

Code:
ERROR parsing EPG message start time of:java.lang.NumberFormatException: For input string: "(null)"
messages in my sagetv_0.txt file. The corresponding EPG data looks e.g. like this:

Code:
EPG-1|41985-1101-28461 DT|(null)|17700|deu|[set=ISO-8859-9][len=12]ARD-Popnacht|[set=ISO-8859-9][len=92]1:00 - 1:03 Nachrichten2:00 - 2:03 Nachrichten3:00 - 3:03 Nachrichten4:00 - 4:03 Nachrichten|||
As one can see, the start time is really "(null)". Where does this data come from? Is it sent like this via dvb or is it constructed somewhere? What could be the reason for the "(null)" string?

greetings
Ken
Reply With Quote
  #2  
Old 01-23-2017, 01:18 PM
Narflex's Avatar
Narflex Narflex is offline
Sage
 
Join Date: Feb 2003
Location: Redondo Beach, CA
Posts: 6,349
This is sent from the native TS parsing code when it encounters EPG data information in the stream and sends the notification back to the Java layer for integration into the database. I'm not sure what would cause the 'null' entry like that though.
__________________
Jeffrey Kardatzke
Google
Founder of SageTV
Reply With Quote
  #3  
Old 01-24-2017, 05:41 AM
kenfox kenfox is offline
Sage User
 
Join Date: Oct 2016
Location: Germany
Posts: 69
Digging a while, I finally found it. The EPG string is constructed in

native/ax/Native2.0/NativeCore/DVBPSIParser.c

In function DVBFormatEPG the function UTCFormat (from PSIParser.c) is called.

UTCFormat is defined like this:

Code:
char* UTCFormat( uint32_t t, char* p, int len )
{
	static char utc_time[30];
	struct tm *utc;
	utc = localtime( (const time_t *)&t );
	if ( utc != NULL && utc->tm_isdst )
	{
		t -= 3600;
		utc = localtime( (const time_t *)&t );  //revseral from mktime()
	}
       ... 8< (snip) ...
	return p;
}
Dangerous parts in this function are the calls to

utc = localtime( (const time_t *)&t );

time_t is a wishy-washy type, as can be read here: stackoverflow

On some linux systems, one can NOT cast a uint32_t to time_t by using a pointer. Which means:

Code:
uint32_t wrongTimeType = ...;

localtime ( (const time_t*)&wrongTimeType );
won't work. Instead, one has to make a real cast like this:

Code:
uint32_t wrongTimeType = ...;
time_t rightTimeType;

rightTimeType = (time_t)wrongTimeType;

localtime ( &rightTimeType );
Doing so, the "(null)" string in the EPG data vanishes.

I will check the rest of the code, if there are other calls to localtime() with the wrong time.

Ken

Last edited by kenfox; 01-24-2017 at 07:38 AM. Reason: Better link for explaining time_t
Reply With Quote
  #4  
Old 01-24-2017, 12:52 PM
Narflex's Avatar
Narflex Narflex is offline
Sage
 
Join Date: Feb 2003
Location: Redondo Beach, CA
Posts: 6,349
Great, thanks for tracking that down.
__________________
Jeffrey Kardatzke
Google
Founder of SageTV
Reply With Quote
  #5  
Old 01-25-2017, 10:06 AM
kenfox kenfox is offline
Sage User
 
Join Date: Oct 2016
Location: Germany
Posts: 69
I've checked the native folder and found occurences only in SIParser.c and PSIParser.c. I've change my code locally like this:

SIParser.c, line 1179 to 1182
Code:
	//BUGFIX: Do a real cast to time_t
	time_t rawTime = (time_t)(pEit->start_time);
	//BUGFIX: Use &rawTime instead of (const time_t *)&pEit->start_time
	utc = localtime( &rawTime );  //revseral from mktime()
PSIParser.c, line 529 to 538
Code:
	//BUGFIX: Do a real cast to time_t
	time_t rawTime = (time_t)t;
	//BUGFIX: Use &rawTime instead of (const time_t *)&t
	utc = localtime( &rawTime );  
	if ( utc != NULL && utc->tm_isdst )
	{
		t -= 3600;
		//BUGFIX: Use &rawTime instead of (const time_t *)&t
		utc = localtime( &rawTime );  //revseral from mktime()
	}
Before submitting a patch, I'd suggest that someone should test the changes where the code did work in the first place. So it will be shure, it works on various systems.
Reply With Quote
  #6  
Old 01-25-2017, 01:39 PM
Narflex's Avatar
Narflex Narflex is offline
Sage
 
Join Date: Feb 2003
Location: Redondo Beach, CA
Posts: 6,349
I'm not sure you'll get much feedback on someone testing a change like that. You can go ahead and submit a pull request and I'll have somebody else who knows this kind of stuff better than I do take a look and let me know if they see any problems...but to me, it looks like it's a safe change.
__________________
Jeffrey Kardatzke
Google
Founder of SageTV
Reply With Quote
  #7  
Old 01-25-2017, 08:24 PM
wnjj wnjj is offline
Sage Icon
 
Join Date: Jan 2009
Posts: 1,514
It's pretty safe to just include since it's just casting before use but it looks like you've introduced a bug with the DST 'if' statement. You need to recast the new value of 't' into 'rawTime' after subtracting 3600:

Code:
	//BUGFIX: Do a real cast to time_t
	time_t rawTime = (time_t)t;
	//BUGFIX: Use &rawTime instead of (const time_t *)&t
	utc = localtime( &rawTime );  
	if ( utc != NULL && utc->tm_isdst )
	{
		t -= 3600;
		rawTime = (time_t)t;
		//BUGFIX: Use &rawTime instead of (const time_t *)&t
		utc = localtime( &rawTime );  //revseral from mktime()
	}
Reply With Quote
  #8  
Old 01-26-2017, 01:23 AM
kenfox kenfox is offline
Sage User
 
Join Date: Oct 2016
Location: Germany
Posts: 69
Quote:
Originally Posted by wnjj View Post
but it looks like you've introduced a bug with the DST 'if' statement. You need to recast the new value of 't' into 'rawTime' after subtracting 3600
Yeah man, you are right! Thanx for takeing a look at it.
Reply With Quote
  #9  
Old 02-02-2017, 05:30 AM
kenfox kenfox is offline
Sage User
 
Join Date: Oct 2016
Location: Germany
Posts: 69
So here is the patch. Please review it.

Code:
From e0b915b7a167e49ea0d536d32185b8c5e4a8ae81 Mon Sep 17 00:00:00 2001
From: Ken Fox <kenfox@outlook.de>
Date: Thu, 2 Feb 2017 12:19:44 +0100
Subject: [PATCH 1/2] Doing a real cast for time_t, because casting a time_t
 pointer is dangerous

---
 native/ax/Native2.0/NativeCore/PSIParser.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/native/ax/Native2.0/NativeCore/PSIParser.c b/native/ax/Native2.0/NativeCore/PSIParser.c
index 3429223..ff5ed10 100644
--- a/native/ax/Native2.0/NativeCore/PSIParser.c
+++ b/native/ax/Native2.0/NativeCore/PSIParser.c
@@ -526,12 +526,15 @@ char* UTCFormat( uint32_t t, char* p, int len )
 {
 	static char utc_time[30];
 	struct tm *utc;
-	utc = localtime( (const time_t *)&t );  
+	//Be shure to do a real cast:
+	time_t rawTime = (time_t)t;
+	utc = localtime( &rawTime );  
 	if ( utc != NULL && utc->tm_isdst )
 	{
 		t -= 3600;
-		utc = localtime( (const time_t *)&t );  //revseral from mktime()
-	}
+		rawTime = (time_t)t;
+		utc = localtime( &rawTime );  //revseral from mktime()
+	}  
 	if ( utc == NULL ) return 0;
 	if ( p == NULL || len == 0)
 	{
-- 
2.11.0.windows.1


From 6f2c33347cdadec1d3dcc3f44e282c5269fb3fa3 Mon Sep 17 00:00:00 2001
From: Ken Fox <kenfox@outlook.de>
Date: Thu, 2 Feb 2017 12:25:39 +0100
Subject: [PATCH 2/2] Doing a real cast for time_t, becaus casting a time_t
 pointer is dangerous

---
 native/ax/TSnative/SIParser.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/native/ax/TSnative/SIParser.c b/native/ax/TSnative/SIParser.c
index 223a325..ca37e0e 100644
--- a/native/ax/TSnative/SIParser.c
+++ b/native/ax/TSnative/SIParser.c
@@ -1176,7 +1176,9 @@ int EPGNotifyDVB( SI_PARSER* pParser, DEIT* pEit )
 	
 	//lt = pEit->start_time - 315532800+6*3600*24;    //convert to start time 1/6/1980 from 1/1/1970  
 	//lt = pEit->start_time - 315964800;
-	utc = localtime( (const time_t *)&pEit->start_time );  //revseral from mktime()
+	//Be shure to do a real cast:
+	time_t rawTime = (time_t)(pEit->start_time);
+	utc = localtime( &rawTime );  //revseral from mktime()
 	if ( utc == NULL ) return 0;
 
 	utc->tm_hour -= utc->tm_isdst > 0 ? 1 : 0;  //get ridee of saving time
-- 
2.11.0.windows.1
Reply With Quote
  #10  
Old 02-02-2017, 11:03 AM
wnjj wnjj is offline
Sage Icon
 
Join Date: Jan 2009
Posts: 1,514
Looks good to me,
Reply With Quote
  #11  
Old 02-03-2017, 02:18 PM
Narflex's Avatar
Narflex Narflex is offline
Sage
 
Join Date: Feb 2003
Location: Redondo Beach, CA
Posts: 6,349
Go ahead and submit your pull request.
__________________
Jeffrey Kardatzke
Google
Founder of SageTV
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting based on released date and add to library date not working still Gustovier Diamond 35 03-15-2011 12:45 PM
Automatic Metadata Failed (Code 10100) IMDB: Failed to parse providerDataUrl: mkanet Batch Metadata Tools 2 10-12-2010 03:22 PM
How to Display Recordings by Recording Date & Original Air Date joe123 SageTV Customizations 25 02-16-2010 05:28 AM
6.2.4-SagetvService:timeout,failed to start DRAK SageTV Beta Test Software 11 07-11-2007 06:05 AM
How does 6.0.13 parse .mov and .hdmov ? corykim SageTV Beta Test Software 0 11-13-2006 06:51 PM


All times are GMT -6. The time now is 12:48 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.