Skip to content

Commit ba70ea7

Browse files
authored
Merge pull request #1450 from G-flat/fix_soundcloud_track_id_overflow
[SoundCloud] Use long integers (64-bit) for track IDs to prevent overflows
2 parents 15936b1 + df10cc1 commit ba70ea7

183 files changed

Lines changed: 2535 additions & 2185 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ public InfoItemsPage<StreamInfoItem> getInitialPage() {
149149
streamInfoItemsCollector.commit(
150150
new SoundcloudStreamInfoItemExtractor(track));
151151
} else {
152-
// %09d would be enough, but a 0 before the number does not create
153-
// problems, so let's be sure
154-
ids.add(String.format("%010d", track.getInt("id")));
152+
ids.add(String.valueOf(track.getLong("id")));
155153
}
156154
});
157155

@@ -187,15 +185,15 @@ public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException
187185
final JsonArray tracks = JsonParser.array().from(response);
188186
// Response may not contain tracks in the same order as currentIds.
189187
// The streams are displayed in the order which is used in currentIds on SoundCloud.
190-
final HashMap<Integer, JsonObject> idToTrack = new HashMap<>();
188+
final HashMap<Long, JsonObject> idToTrack = new HashMap<>();
191189
for (final Object track : tracks) {
192190
if (track instanceof JsonObject) {
193191
final JsonObject o = (JsonObject) track;
194-
idToTrack.put(o.getInt("id"), o);
192+
idToTrack.put(o.getLong("id"), o);
195193
}
196194
}
197195
for (final String strId : currentIds) {
198-
final int id = Integer.parseInt(strId);
196+
final long id = Long.parseLong(strId);
199197
try {
200198
collector.commit(new SoundcloudStreamInfoItemExtractor(
201199
Objects.requireNonNull(

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
7979
@Nonnull
8080
@Override
8181
public String getId() {
82-
return String.valueOf(track.getInt("id"));
82+
return String.valueOf(track.getLong("id"));
8383
}
8484

8585
@Nonnull

extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorTest.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,80 @@ public void testAudioStreams() throws Exception {
217217
});
218218
}
219219
}
220+
221+
@Nested
222+
class SmallTrackId extends DefaultStreamExtractorTest {
223+
private static final String ID = "technicality";
224+
private static final String UPLOADER = SOUNDCLOUD + "garrett-cameron-1";
225+
private static final int TIMESTAMP = 34;
226+
private static final String URL = UPLOADER + "/" + ID + "#t=" + TIMESTAMP;
227+
228+
@Override
229+
protected StreamExtractor createExtractor() throws Exception {
230+
return SoundCloud.getStreamExtractor(URL);
231+
}
232+
233+
@Override public StreamingService expectedService() { return SoundCloud; }
234+
@Override public String expectedName() { return "Technicality"; }
235+
@Override public String expectedId() { return "135535700"; }
236+
@Override public String expectedUrlContains() { return UPLOADER + "/" + ID; }
237+
@Override public String expectedOriginalUrlContains() { return URL; }
238+
239+
@Override public StreamType expectedStreamType() { return StreamType.AUDIO_STREAM; }
240+
@Override public String expectedUploaderName() { return "Samuel Cameron (ZVW)"; }
241+
@Override public String expectedUploaderUrl() { return UPLOADER; }
242+
@Override public boolean expectedDescriptionIsEmpty() { return true; }
243+
@Override public List<String> expectedDescriptionContains() { return Collections.emptyList(); }
244+
@Override public long expectedLength() { return 182; }
245+
@Override public long expectedTimestamp() { return TIMESTAMP; }
246+
@Override public long expectedViewCountAtLeast() { return 16; }
247+
@Nullable @Override public String expectedUploadDate() { return "2014-02-18 21:25:01.000"; }
248+
@Nullable @Override public String expectedTextualUploadDate() { return "2014-02-18T21:25:01Z"; }
249+
@Override public long expectedLikeCountAtLeast() { return 1; }
250+
@Override public long expectedDislikeCountAtLeast() { return -1; }
251+
@Override public boolean expectedHasVideoStreams() { return false; }
252+
@Override public boolean expectedHasSubtitles() { return false; }
253+
@Override public boolean expectedHasFrames() { return false; }
254+
@Override public int expectedStreamSegmentsCount() { return 0; }
255+
@Override public String expectedLicence() { return "all-rights-reserved"; }
256+
@Override public String expectedCategory() { return "Electronic"; }
257+
}
258+
259+
@Nested
260+
class LongTrackId extends DefaultStreamExtractorTest {
261+
private static final String ID = "hard-to-break";
262+
private static final String UPLOADER = SOUNDCLOUD + "blakewhiten";
263+
private static final int TIMESTAMP = 130;
264+
private static final String URL = UPLOADER + "/" + ID + "#t=" + TIMESTAMP;
265+
266+
@Override
267+
protected StreamExtractor createExtractor() throws Exception {
268+
return SoundCloud.getStreamExtractor(URL);
269+
}
270+
271+
@Override public StreamingService expectedService() { return SoundCloud; }
272+
@Override public String expectedName() { return "Hard to Break"; }
273+
@Override public String expectedId() { return "2167944333"; }
274+
@Override public String expectedUrlContains() { return UPLOADER + "/" + ID; }
275+
@Override public String expectedOriginalUrlContains() { return URL; }
276+
277+
@Override public StreamType expectedStreamType() { return StreamType.AUDIO_STREAM; }
278+
@Override public String expectedUploaderName() { return "Blake Whiten"; }
279+
@Override public String expectedUploaderUrl() { return UPLOADER; }
280+
@Override public boolean expectedDescriptionIsEmpty() { return true; }
281+
@Override public List<String> expectedDescriptionContains() { return Collections.emptyList(); }
282+
@Override public long expectedLength() { return 201; }
283+
@Override public long expectedTimestamp() { return TIMESTAMP; }
284+
@Override public long expectedViewCountAtLeast() { return 120222; }
285+
@Nullable @Override public String expectedUploadDate() { return "2025-09-10 02:24:00.000"; }
286+
@Nullable @Override public String expectedTextualUploadDate() { return "2025-09-10T02:24:00Z"; }
287+
@Override public long expectedLikeCountAtLeast() { return 1970; }
288+
@Override public long expectedDislikeCountAtLeast() { return -1; }
289+
@Override public boolean expectedHasVideoStreams() { return false; }
290+
@Override public boolean expectedHasSubtitles() { return false; }
291+
@Override public boolean expectedHasFrames() { return false; }
292+
@Override public int expectedStreamSegmentsCount() { return 0; }
293+
@Override public String expectedLicence() { return "all-rights-reserved"; }
294+
@Override public String expectedCategory() { return "Country"; }
295+
}
220296
}

extractor/src/test/resources/mocks/v1/org/schabi/newpipe/extractor/services/soundcloud/search/soundcloudsearchextractor/all/generated_mock_0.json

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

extractor/src/test/resources/mocks/v1/org/schabi/newpipe/extractor/services/soundcloud/search/soundcloudsearchextractor/all/generated_mock_1.json

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

extractor/src/test/resources/mocks/v1/org/schabi/newpipe/extractor/services/soundcloud/search/soundcloudsearchextractor/nonextpage/generated_mock_0.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"request": {
33
"httpMethod": "GET",
4-
"url": "https://api-v2.soundcloud.com/search?q\u003dwpgh%C3%BC%C3%A4\u0026client_id\u003dMoLbAg35TuqjYwWVtNIKyRPFScQGMOBY\u0026limit\u003d10\u0026offset\u003d0",
4+
"url": "https://api-v2.soundcloud.com/search?q\u003dwpgh%C3%BC%C3%A4\u0026client_id\u003dCkCiIyf14rHi27fhk7HxhPOzc85okfSJ\u0026limit\u003d10\u0026offset\u003d0",
55
"headers": {
66
"Accept-Language": [
77
"en-GB, en;q\u003d0.9"
@@ -26,7 +26,7 @@
2626
"application/json; charset\u003dutf-8"
2727
],
2828
"date": [
29-
"Sat, 12 Jul 2025 10:24:21 GMT"
29+
"Sat, 21 Feb 2026 01:08:32 GMT"
3030
],
3131
"referrer-policy": [
3232
"no-referrer"
@@ -41,13 +41,13 @@
4141
"Origin"
4242
],
4343
"via": [
44-
"1.1 cbad29402e4e90baabe7151c3f1203b6.cloudfront.net (CloudFront)"
44+
"1.1 cb2b840821313909da7f7890ec5606ba.cloudfront.net (CloudFront)"
4545
],
4646
"x-amz-cf-id": [
47-
"dzL6w9UaEREDBeOHXXNDtPTsdqPoQdIeDb3l5Q_QtN6jqFBEXG9MhQ\u003d\u003d"
47+
"Vm55G14YlC-_pq2Ll2GMbvwX-uRz904SxMTr5Tu4d-zCo3A6RTTiRw\u003d\u003d"
4848
],
4949
"x-amz-cf-pop": [
50-
"FRA56-P11"
50+
"HAM50-P5"
5151
],
5252
"x-cache": [
5353
"Miss from cloudfront"
@@ -62,7 +62,7 @@
6262
"noindex"
6363
]
6464
},
65-
"responseBody": "{\"collection\":[{\"avatar_url\":\"https://i1.sndcdn.com/avatars-PU8AmxubPTAMnl0t-zad7tA-large.jpg\",\"city\":null,\"comments_count\":0,\"country_code\":null,\"created_at\":\"2022-02-28T12:42:23Z\",\"creator_subscriptions\":[{\"product\":{\"id\":\"free\"}}],\"creator_subscription\":{\"product\":{\"id\":\"free\"}},\"description\":null,\"followers_count\":0,\"followings_count\":0,\"first_name\":\"Weghua\",\"full_name\":\"Weghua Habibu\",\"groups_count\":0,\"id\":1091242897,\"kind\":\"user\",\"last_modified\":\"2022-02-28T12:42:35Z\",\"last_name\":\"Habibu\",\"likes_count\":0,\"playlist_likes_count\":0,\"permalink\":\"weghua-habibu\",\"permalink_url\":\"https://soundcloud.com/weghua-habibu\",\"playlist_count\":0,\"reposts_count\":null,\"track_count\":0,\"uri\":\"https://api.soundcloud.com/users/1091242897\",\"urn\":\"soundcloud:users:1091242897\",\"username\":\"Weghua Habibu\",\"verified\":false,\"visuals\":null,\"badges\":{\"pro\":false,\"creator_mid_tier\":false,\"pro_unlimited\":false,\"verified\":false},\"station_urn\":\"soundcloud:system-playlists:artist-stations:1091242897\",\"station_permalink\":\"artist-stations:1091242897\",\"date_of_birth\":{\"month\":2,\"year\":1973,\"day\":1}},{\"avatar_url\":\"https://i1.sndcdn.com/avatars-000360777944-r6mq9y-large.jpg\",\"city\":null,\"comments_count\":0,\"country_code\":null,\"created_at\":\"2017-12-05T08:50:01Z\",\"creator_subscriptions\":[{\"product\":{\"id\":\"free\"}}],\"creator_subscription\":{\"product\":{\"id\":\"free\"}},\"description\":null,\"followers_count\":0,\"followings_count\":0,\"first_name\":\"Wpg\",\"full_name\":\"Wpg Ua\",\"groups_count\":0,\"id\":360091154,\"kind\":\"user\",\"last_modified\":\"2017-12-05T08:50:02Z\",\"last_name\":\"Ua\",\"likes_count\":0,\"playlist_likes_count\":0,\"permalink\":\"wpg-ua\",\"permalink_url\":\"https://soundcloud.com/wpg-ua\",\"playlist_count\":0,\"reposts_count\":null,\"track_count\":0,\"uri\":\"https://api.soundcloud.com/users/360091154\",\"urn\":\"soundcloud:users:360091154\",\"username\":\"Wpg Ua\",\"verified\":false,\"visuals\":null,\"badges\":{\"pro\":false,\"creator_mid_tier\":false,\"pro_unlimited\":false,\"verified\":false},\"station_urn\":\"soundcloud:system-playlists:artist-stations:360091154\",\"station_permalink\":\"artist-stations:360091154\",\"date_of_birth\":null},{\"avatar_url\":\"https://a1.sndcdn.com/images/default_avatar_large.png\",\"city\":\"\",\"comments_count\":0,\"country_code\":\"CA\",\"created_at\":\"2017-08-05T22:17:50Z\",\"creator_subscriptions\":[{\"product\":{\"id\":\"free\"}}],\"creator_subscription\":{\"product\":{\"id\":\"free\"}},\"description\":\"\",\"followers_count\":0,\"followings_count\":1,\"first_name\":\"Douglas\",\"full_name\":\"Douglas Chua\",\"groups_count\":0,\"id\":324448453,\"kind\":\"user\",\"last_modified\":\"2017-08-05T22:18:05Z\",\"last_name\":\"Chua\",\"likes_count\":0,\"playlist_likes_count\":0,\"permalink\":\"douglaswpchua\",\"permalink_url\":\"https://soundcloud.com/douglaswpchua\",\"playlist_count\":0,\"reposts_count\":null,\"track_count\":0,\"uri\":\"https://api.soundcloud.com/users/324448453\",\"urn\":\"soundcloud:users:324448453\",\"username\":\"DouglasWPChua\",\"verified\":false,\"visuals\":null,\"badges\":{\"pro\":false,\"creator_mid_tier\":false,\"pro_unlimited\":false,\"verified\":false},\"station_urn\":\"soundcloud:system-playlists:artist-stations:324448453\",\"station_permalink\":\"artist-stations:324448453\",\"date_of_birth\":{\"month\":5,\"year\":1976,\"day\":1}}],\"total_results\":3,\"query_urn\":\"soundcloud:search:147d8013fd614c08a31215017d95cf50\"}",
66-
"latestUrl": "https://api-v2.soundcloud.com/search?q\u003dwpgh%C3%BC%C3%A4\u0026client_id\u003dMoLbAg35TuqjYwWVtNIKyRPFScQGMOBY\u0026limit\u003d10\u0026offset\u003d0"
65+
"responseBody": "{\"collection\":[{\"avatar_url\":\"https://i1.sndcdn.com/avatars-000360777944-r6mq9y-large.jpg\",\"city\":null,\"comments_count\":0,\"country_code\":null,\"created_at\":\"2017-12-05T08:50:01Z\",\"creator_subscriptions\":[{\"product\":{\"id\":\"free\"}}],\"creator_subscription\":{\"product\":{\"id\":\"free\"}},\"description\":null,\"followers_count\":0,\"followings_count\":0,\"first_name\":\"Wpg\",\"full_name\":\"Wpg Ua\",\"groups_count\":0,\"id\":360091154,\"kind\":\"user\",\"last_modified\":\"2017-12-05T08:50:02Z\",\"last_name\":\"Ua\",\"likes_count\":0,\"playlist_likes_count\":0,\"permalink\":\"wpg-ua\",\"permalink_url\":\"https://soundcloud.com/wpg-ua\",\"playlist_count\":0,\"reposts_count\":null,\"track_count\":0,\"uri\":\"https://api.soundcloud.com/users/soundcloud%3Ausers%3A360091154\",\"urn\":\"soundcloud:users:360091154\",\"username\":\"Wpg Ua\",\"verified\":false,\"visuals\":null,\"badges\":{\"pro\":false,\"creator_mid_tier\":false,\"pro_unlimited\":false,\"verified\":false},\"station_urn\":\"soundcloud:system-playlists:artist-stations:360091154\",\"station_permalink\":\"artist-stations:360091154\",\"date_of_birth\":null},{\"avatar_url\":\"https://i1.sndcdn.com/avatars-PU8AmxubPTAMnl0t-zad7tA-large.jpg\",\"city\":null,\"comments_count\":0,\"country_code\":null,\"created_at\":\"2022-02-28T12:42:23Z\",\"creator_subscriptions\":[{\"product\":{\"id\":\"free\"}}],\"creator_subscription\":{\"product\":{\"id\":\"free\"}},\"description\":null,\"followers_count\":0,\"followings_count\":0,\"first_name\":\"Weghua\",\"full_name\":\"Weghua Habibu\",\"groups_count\":0,\"id\":1091242897,\"kind\":\"user\",\"last_modified\":\"2022-02-28T12:42:35Z\",\"last_name\":\"Habibu\",\"likes_count\":0,\"playlist_likes_count\":0,\"permalink\":\"weghua-habibu\",\"permalink_url\":\"https://soundcloud.com/weghua-habibu\",\"playlist_count\":0,\"reposts_count\":null,\"track_count\":0,\"uri\":\"https://api.soundcloud.com/users/soundcloud%3Ausers%3A1091242897\",\"urn\":\"soundcloud:users:1091242897\",\"username\":\"Weghua Habibu\",\"verified\":false,\"visuals\":null,\"badges\":{\"pro\":false,\"creator_mid_tier\":false,\"pro_unlimited\":false,\"verified\":false},\"station_urn\":\"soundcloud:system-playlists:artist-stations:1091242897\",\"station_permalink\":\"artist-stations:1091242897\",\"date_of_birth\":null},{\"avatar_url\":\"https://a1.sndcdn.com/images/default_avatar_large.png\",\"city\":\"\",\"comments_count\":0,\"country_code\":\"CA\",\"created_at\":\"2017-08-05T22:17:50Z\",\"creator_subscriptions\":[{\"product\":{\"id\":\"free\"}}],\"creator_subscription\":{\"product\":{\"id\":\"free\"}},\"description\":\"\",\"followers_count\":0,\"followings_count\":1,\"first_name\":\"Douglas\",\"full_name\":\"Douglas Chua\",\"groups_count\":0,\"id\":324448453,\"kind\":\"user\",\"last_modified\":\"2017-08-05T22:18:05Z\",\"last_name\":\"Chua\",\"likes_count\":0,\"playlist_likes_count\":0,\"permalink\":\"douglaswpchua\",\"permalink_url\":\"https://soundcloud.com/douglaswpchua\",\"playlist_count\":0,\"reposts_count\":null,\"track_count\":0,\"uri\":\"https://api.soundcloud.com/users/soundcloud%3Ausers%3A324448453\",\"urn\":\"soundcloud:users:324448453\",\"username\":\"DouglasWPChua\",\"verified\":false,\"visuals\":null,\"badges\":{\"pro\":false,\"creator_mid_tier\":false,\"pro_unlimited\":false,\"verified\":false},\"station_urn\":\"soundcloud:system-playlists:artist-stations:324448453\",\"station_permalink\":\"artist-stations:324448453\",\"date_of_birth\":null}],\"total_results\":3,\"query_urn\":\"soundcloud:search:621caed9c6f24445bee3d04a783338aa\"}",
66+
"latestUrl": "https://api-v2.soundcloud.com/search?q\u003dwpgh%C3%BC%C3%A4\u0026client_id\u003dCkCiIyf14rHi27fhk7HxhPOzc85okfSJ\u0026limit\u003d10\u0026offset\u003d0"
6767
}
6868
}

extractor/src/test/resources/mocks/v1/org/schabi/newpipe/extractor/services/soundcloud/search/soundcloudsearchextractor/paging/generated_mock_0.json

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

extractor/src/test/resources/mocks/v1/org/schabi/newpipe/extractor/services/soundcloud/search/soundcloudsearchextractor/paging/generated_mock_1.json

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

extractor/src/test/resources/mocks/v1/org/schabi/newpipe/extractor/services/soundcloud/search/soundcloudsearchextractor/playlists/generated_mock_0.json

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

extractor/src/test/resources/mocks/v1/org/schabi/newpipe/extractor/services/soundcloud/search/soundcloudsearchextractor/playlists/generated_mock_1.json

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)