Bug 134301 - rssfilter crashes ktorrent when processing openoffice rss
Summary: rssfilter crashes ktorrent when processing openoffice rss
Status: RESOLVED FIXED
Alias: None
Product: ktorrent
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR crash
Target Milestone: ---
Assignee: Alan Jones
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-19 00:29 UTC by Clara Gnos
Modified: 2006-10-02 19:49 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Fixes Crash in RssFilter::deleteMatch (719 bytes, patch)
2006-10-02 15:01 UTC, Clara Gnos
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Clara Gnos 2006-09-19 00:29:28 UTC
Version:           svn 586177 (using KDE KDE 3.5.4)
Installed from:    Gentoo Packages
Compiler:          gcc-Version 4.1.1 (Gentoo 4.1.1-r1) 
OS:                Linux

When I open openoffice rss http://borft.student.utwente.nl/~mike/oo/bt.rss (no other rss), set it active, add filter with .* as filter, activate it and press Process it will crash:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1210104144 (LWP 21575)]
0x42e85289 in QString::QString () from /usr/qt/3/lib/libqt-mt.so.3
(gdb) bt
#0  0x42e85289 in QString::QString () from /usr/qt/3/lib/libqt-mt.so.3
#1  0xb77db914 in kt::FilterMatch::link (this=0x8) at rssfilter.h:52
#2  0xb77e0213 in kt::RssFilter::deleteMatch (this=0x8434430, link=@0xbfc70ad8) at rssfilter.cpp:343
#3  0xb77d825e in kt::RssFeedManager::scanArticle (this=0x83e3890, article=@0xbfc70bd4, filter=0x8434430) at rssfeedmanager.cpp:1324
#4  0xb77d8600 in kt::RssFeedManager::rescanFilter (this=0x83e3890) at rssfeedmanager.cpp:1353
#5  0xb77f1d4c in kt::RssFeedManager::qt_invoke (this=0x83e3890, _id=86, _o=0xbfc70fa8) at rssfeedmanager.moc.cpp:277
#6  0x42bbb8c9 in QObject::activate_signal () from /usr/qt/3/lib/libqt-mt.so.3
#7  0x42bbc51d in QObject::activate_signal () from /usr/qt/3/lib/libqt-mt.so.3
#8  0xb77f0753 in kt::RssFilter::rescanFilter (this=0x8434430) at rssfilter.moc.cpp:261
#9  0xb77f0df3 in kt::RssFilter::qt_emit (this=0x8434430, _id=12, _o=0xbfc71078) at rssfilter.moc.cpp:296
#10 0x42bbb90b in QObject::activate_signal () from /usr/qt/3/lib/libqt-mt.so.3
#11 0x42bbc51d in QObject::activate_signal () from /usr/qt/3/lib/libqt-mt.so.3
#12 0x42ef4b4c in QButton::clicked () from /usr/qt/3/lib/libqt-mt.so.3
#13 0x42c4e02d in QButton::mouseReleaseEvent () from /usr/qt/3/lib/libqt-mt.so.3
#14 0x42bf3bfa in QWidget::event () from /usr/qt/3/lib/libqt-mt.so.3
#15 0x42b5ce07 in QApplication::internalNotify () from /usr/qt/3/lib/libqt-mt.so.3
#16 0x42b5db59 in QApplication::notify () from /usr/qt/3/lib/libqt-mt.so.3
#17 0x4328a92f in KApplication::notify () from /usr/kde/3.5/lib/libkdecore.so.4
#18 0xbfc71860 in ?? ()
#19 0x08403220 in ?? ()
#20 0xbfc713dc in ?? ()
#21 0x428365d4 in ?? () from /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/libstdc++.so.6
---Type <return> to continue, or q <return> to quit---
#22 0x08411a58 in ?? ()
#23 0x083fa248 in ?? ()
#24 0xbfc712a8 in ?? ()
#25 0x4280f141 in operator delete () from /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/libstdc++.so.6
Previous frame inner to this frame (corrupt stack?)




Loaded plugins: infowidgetplugin, ipfilterplugin, partfileimporter, rssfeedplugin, scanfolderplugin
KDE: 3.5.4
Qt: 3.3.6
Comment 1 Alan Jones 2006-09-29 22:19:12 UTC
SVN commit 590329 by skyphyr:

BUG: 134301
Rewrite of the download management - includes a new class to handle managing downloads in place of KIO::NetAccess


 M  +2 -2      Makefile.am  
 M  +2 -2      rssfeed.cpp  
 M  +7 -163    rssfeedmanager.cpp  
 M  +0 -2      rssfeedmanager.h  
 M  +1 -1      rssfilter.cpp  
 A             rsslinkdownloader.cpp   [License: GPL (v2+)]
 A             rsslinkdownloader.h   [License: GPL (v2+)]


--- trunk/extragear/network/ktorrent/plugins/rssfeed/Makefile.am #590328:590329
@@ -20,9 +20,9 @@
 kde_services_DATA = ktrssfeedplugin.desktop
 
 noinst_HEADERS = rssfeedplugin.h rssfeedmanager.h rssfeed.h rssfilter.h \
-	rssarticle.h
+		rssarticle.h rsslinkdownloader.h
 ktrssfeedplugin_la_SOURCES = rssfeedplugin.cpp rssfeedmanager.cpp \
-		rssfeedwidget.ui rssfeed.cpp rssfilter.cpp rssarticle.cpp
+			rssfeedwidget.ui rssfeed.cpp rssfilter.cpp rssarticle.cpp rsslinkdownloader.cpp
 ktrssfeedplugin_la_LIBADD = rss/librsslocal.la ../../libktorrent/torrent/libtorrent.la \
 	../../libktorrent/libktorrent.la $(LIB_KHTML) $(LIB_KPARTS)
 
--- trunk/extragear/network/ktorrent/plugins/rssfeed/rssfeed.cpp #590328:590329
@@ -1,6 +1,6 @@
 /***************************************************************************
- *   Copyright (C) 2005 by Joris Guisson                                   *
- *   joris.guisson@gmail.com                                               *
+ *   Copyright (C) 2006 by Alan Jones                                      *
+ *   skyphyr@gmail.com                                                     *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
--- trunk/extragear/network/ktorrent/plugins/rssfeed/rssfeedmanager.cpp #590328:590329
@@ -25,7 +25,7 @@
 #include <kio/netaccess.h>
 #include <kstandarddirs.h>
 #include <keditlistbox.h>
-#include <kmimetype.h>
+// #include <kmimetype.h>
 #include <kmessagebox.h>
 
 #include <qstring.h>
@@ -53,6 +53,8 @@
 #include "../../libktorrent/torrent/bdecoder.h"
 #include "../../libktorrent/torrent/bnode.h"
 
+#include "rsslinkdownloader.h"
+
 using namespace bt;
 
 namespace kt
@@ -137,76 +139,6 @@
 		//Destruct the manager
 	}
 	
-	bool RssFeedManager::processHtml(const QString &link, const QString &filename, bool silent)
-	{
-		KURL url = link;
-		//let's open the file
-		QFile file(filename);
-		
-		if (!file.exists())
-		{
-			return false;
-		}
-		
-		if (!file.open(IO_ReadOnly))
-		{
-			return false;
-		}
-		
-		QTextStream html(&file);
-		
-		//go through a line at a time checking for a torrent
-		QString htmlline = html.readLine();
-		while (!htmlline.isNull())
-		{
-			QRegExp hrefTags = QString("<A.*HREF.*</A");
-			hrefTags.setCaseSensitive(false);
-			hrefTags.setMinimal(true);
-			
-			int matchPos = 0;
-			while (htmlline.find(hrefTags, matchPos) >= 0)
-			{
-				matchPos += hrefTags.matchedLength();
-				//we're found an <a href tag - let's check it if contains download
-				QRegExp hrefText = QString("d(own)?load");
-				hrefText.setCaseSensitive(false);
-				
-				if (!hrefTags.capturedTexts()[0].contains(hrefText))
-				{
-					//link text doesn't contain dload/download
-					continue;
-				}
-				
-				//we're found an <a href tag - now let's the the url out of it
-				hrefText = QString("HREF=\"?([^\">< ]*)[\" ]");
-				hrefText.setCaseSensitive(false);
-
-				hrefTags.capturedTexts()[0].find(hrefText);
-				//lets get the captured
-				QString hrefLink = hrefText.capturedTexts()[1];
-				
-				if (hrefLink.startsWith("/"))
-				{
-					hrefLink = url.protocol() + "://" + url.host() + hrefLink;
-				} else if (!hrefLink.startsWith("http://", false)) {
-					hrefLink = url.url().left(url.url().findRev("/")+1) + hrefLink;
-				}
-				
-				if (processLink(hrefLink, silent, true))
-					{
-					return true;
-					}
-			
-			}
-			
-			//run the query again
-			htmlline = html.readLine();
-		}
-		
-		
-		return false;
-	}
-	
 	void RssFeedManager::clearArticles()
 	{
 		int pos = feeds.find((RssFeed *)sender());
@@ -227,81 +159,6 @@
 		refreshFeed->setEnabled(!feedUrl->url().isEmpty());
 	}
 	
-	bool RssFeedManager::processLink(const QString &link, bool silent, bool noHtml)
-	{
-		//m_core->loadSilently(torrent);
-		KMimeType linkType = *KMimeType::findByURL(link);
-		QString filename;
-		if( !KIO::NetAccess::download( link, filename, qApp->mainWidget() ) )
-		{
-			Out() << "couldn't download file: %s" << link.ascii() << endl;
-			return false;
-		}
-		
-		linkType = *KMimeType::findByFileContent(filename);
-		if (linkType.is("text/html"))
-		{
-			if (!noHtml)
-			{
-				return processHtml(link, filename, silent);
-			}
-			return false;
-		}
-		
-		if (linkType.is("application/x-bittorrent"))
-		{
-			if (silent)
-			{
-				m_core->loadSilently( link );
-			}
-			else
-			{
-				m_core->load( link );
-			}
-			return true;
-		}
-		
-		QFile fptr(filename);
-		if (!fptr.open(IO_ReadOnly))
-			return false;
-		
-		QByteArray data(fptr.size());
-		fptr.readBlock(data.data(),fptr.size());
-	
-		try
-		{
-			//last ditched brute force attempt to check if it's a torrent file
-			BNode* node = 0;
-			BDecoder decoder(data,false);
-			node = decoder.decode();
-			BDictNode* dict = dynamic_cast<BDictNode*>(node);
-			
-			if (dict)
-			{
-				delete node;
-				node = dict = 0;
-				
-				if (silent)
-				{
-					m_core->loadSilently( link );
-				}
-				else
-				{
-					m_core->load( link );
-				}
-				return true;
-			}
-			
-		
-		}
-		catch (...)
-		{
-			//we can just ignore any errors here
-		}
-		
-		return false;
-	}
-	
 	void RssFeedManager::connectFeed(int index)
 	{
 	
@@ -898,11 +755,7 @@
 			int endRow = feedArticles->selection(i).topRow() + feedArticles->selection(i).numRows(); 
 			for (int j=feedArticles->selection(i).topRow(); j<endRow; j++)
 			{
-				if (!processLink(feedArticles->text(j, 2), false))
-				{
-					//the file failed to download a torrent
-					KMessageBox::error(0,"Failed to find and download a valid torrent for " + feedArticles->text(j,0));
-				}
+				new RssLinkDownloader(m_core, feedArticles->text(j, 2));
 			}
 		}
 	}
@@ -914,10 +767,7 @@
 			int endRow = filterMatches->selection(i).topRow() + filterMatches->selection(i).numRows(); 
 			for (int j=filterMatches->selection(i).topRow(); j<endRow; j++)
 			{
-				if (!processLink(filterMatches->text(j, 3), false))
-				{
-					KMessageBox::error(0,"Failed to find and download a valid torrent for season " + filterMatches->text(j,0) + " episode " + filterMatches->text(j,1));
-				}
+				new RssLinkDownloader(m_core, filterMatches->text(j, 3));
 			}
 		}
 	}
@@ -1327,10 +1177,7 @@
 			//we were passed a filter - so just scan it with that one
 			if (filter->scanArticle(article))
 			{
-				if (!processLink(article.link().prettyURL()))
-				{
-					filter->deleteMatch(article.link().prettyURL());
-				}
+				new RssLinkDownloader(m_core, article.link().prettyURL(), filter);
 			}
 		}
 		else
@@ -1339,10 +1186,7 @@
 			{
 				if (acceptFilters.at(i)->scanArticle(article))
 				{
-					if (!processLink(article.link().prettyURL()))
-					{
-						acceptFilters.at(i)->deleteMatch(article.link().prettyURL());
-					}
+					new RssLinkDownloader(m_core, article.link().prettyURL(), acceptFilters.at(i));
 				}
 			}
 		}
--- trunk/extragear/network/ktorrent/plugins/rssfeed/rssfeedmanager.h #590328:590329
@@ -58,8 +58,6 @@
 			~RssFeedManager();
 
 		public slots:
-			bool processLink(const QString &link, bool silent = true, bool noHtml = false);
-			bool processHtml(const QString &link, const QString& filename, bool silent = true);
 			void changedActiveFeed();
 			void changedArticleSelection();
 			void changedFeedUrl();
--- trunk/extragear/network/ktorrent/plugins/rssfeed/rssfilter.cpp #590328:590329
@@ -276,7 +276,7 @@
 		if (m_series)
 		{
 			QStringList episodeFormats;
-			episodeFormats << "s([0-9]+)[de]([0-9]+)" << "([0-9]+)x([0-9]+)" << "([0-9]+)([0-9]{2})";
+			episodeFormats << "s([0-9]{1,2})[de]([0-9]{1,2})[^0-9]" << "[^0-9]([0-9]{1,2})x([0-9]{1,2})[^0-9]" << "[^0-9]([0-9]{1,2})([0-9]{2})[^0-9]";
 			for (int i=0; i<episodeFormats.count(); i++)
 			{
 				regEx.setPattern(*episodeFormats.at(i));
Comment 2 Clara Gnos 2006-10-02 14:35:43 UTC
Still crashes here. Used "OOo_\d\.\d\.\d_Win32Intel_install_de_wJRE.exe" as filter. And pressed "Process" manually

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1234221392 (LWP 1238)]
0xb73c928d in QString::QString () from /usr/qt/3/lib/libqt-mt.so.3
(gdb) bt
#0  0xb73c928d in QString::QString () from /usr/qt/3/lib/libqt-mt.so.3
#1  0xb60bc15c in kt::FilterMatch::link (this=0x8521938) at rssfilter.h:52
#2  0xb60c023f in kt::RssFilter::deleteMatch (this=0x85f5c38, link=@0x85f760c) at rssfilter.cpp:343
#3  0xb60c5171 in kt::RssLinkDownloader::processLink (this=0x85f75e0, jobStatus=0x852be40) at rsslinkdownloader.cpp:166
#4  0xb60d3fc1 in kt::RssLinkDownloader::qt_invoke (this=0x85f75e0, _id=2, _o=0xbfd7e694) at rsslinkdownloader.moc.cpp:85
#5  0xb70ff8c9 in QObject::activate_signal () from /usr/qt/3/lib/libqt-mt.so.3
#6  0xb7b439d4 in KIO::Job::result () from /usr/kde/3.5/lib/libkio.so.4
#7  0x0852be40 in ?? ()
#8  0x08521388 in ?? ()
#9  0xbfd7e694 in ?? ()
#10 0xb7b921ac in KIO::Scheduler::_jobFinished () from /usr/kde/3.5/lib/libkio.so.4
#11 0x08284628 in ?? ()
#12 0x086b2db8 in ?? ()
#13 0x08521388 in ?? ()
#14 0x00000000 in ?? ()
Comment 3 Clara Gnos 2006-10-02 14:36:12 UTC
(forgot to reopen it)
Comment 4 Clara Gnos 2006-10-02 15:01:48 UTC
Created attachment 17985 [details]
Fixes Crash in RssFilter::deleteMatch

Wasnt a big problem...you just killed the iterator by removing an item. This
fixes it.
Comment 5 Alan Jones 2006-10-02 19:47:17 UTC
SVN commit 591547 by skyphyr:

BUG: 134301
Removing the iterator caused crashes


 M  +7 -3      rssfilter.cpp  


--- trunk/extragear/network/ktorrent/plugins/rssfeed/rssfilter.cpp #591546:591547
@@ -337,13 +337,17 @@
 	void RssFilter::deleteMatch(const QString& link)
 	{
 	
-		QValueList<FilterMatch>::iterator it;
-		for ( it = m_matches.begin(); it != m_matches.end(); ++it )
+		QValueList<FilterMatch>::iterator it = m_matches.begin();
+		while (it != m_matches.end())
 		{
 			if ((*it).link() == link)
 			{
-				m_matches.remove(it);
+				it = m_matches.remove(it);
 			}
+			else
+			{
+				it++;
+			}
 		}
 		
 	}
Comment 6 Alan Jones 2006-10-02 19:49:15 UTC
Thanks Erdroh - I've applied the patch and put it in svn.

Haven't used iterators before - seems I still need to get used to them
- I had the same error elsewhere in the code earlier - didn't think to
check for other spots I'd used iterators.

Cheers,

Alan.

On 2 Oct 2006 13:01:49 -0000, Erdroh Moshan <ErDroh@gmx.de> wrote:
[bugs.kde.org quoted mail]